akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<int>taro(n), hanako(m);
		int sum_t = 0, sum_h = 0;
		for (int i = 0; i < n; ++i) {
			cin >> taro[i]; sum_t += taro[i];
		}
		for (int i = 0; i < m; ++i) {
			cin >> hanako[i]; sum_h += hanako[i];
		}
		int ans = -1;
		if ((sum_t + sum_h) % 2)ans = -1;
		else {
			if ((sum_h - sum_t) % 2)ans = -1;
			else {
				sort(taro.begin(), taro.end());
				sort(hanako.begin(), hanako.end());
				for (auto x : taro) {
					auto range = equal_range(hanako.begin(), hanako.end(), x + (sum_h - sum_t) / 2);
					if (range.first != range.second) {
						vector<int>::iterator it = range.first;
						ans = *it;
						cout << x << " " << ans << endl;
						break;
					}
				}
			}
		}
		if (ans == -1)cout << ans << endl;
	}
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,m;
	cin>>n>>k;
	long long int a[n+1],f[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	f[1]=0;
	f[2]=abs(a[2]-a[1]);
	for(int i=3;i<=k&&i<=n;i++)
	{
		m=INT_MAX;
		for(int j=1;j<i;j++)
		{
			m=min(m,f[j]+abs(a[i]-a[j]));
		}
		f[i]=m;
	}
	for(int i=k+1;i<=n;i++)
	{
		m=INT_MAX;
		for(int j=i-k;j<i;j++)
		{
			m=min(m,f[j]+abs(a[i]-a[j]));
		}
		f[i]=m;
	}
	cout<<f[n]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string n;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	cout << ((n[0] == n[2]) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,k,q,a,m[100000],i,j;
	scanf("%d %d %d",&n,&k,&q);
	for(i=1;i<=n;i++)	m[i]=k-q;
	for(i=1;i<=q;i++){
		scanf("%d",&a);
		m[a]++;
	}
	for(i=1;i<=n;i++){
		if(m[i]>0){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}


Measured memory_bytes: 896
import sys
flush = sys.stdout.flush
write = sys.stdout.write

N = int(input())

bb_1,bb_2 = "..##",".#.#"
res_1,res_2 = "",""

def ask(s1,s2):
    write(s1+'\n'+s2+'\n')
    result = input()
    flush()
    if result=="end":
        exit()
    return result=="T"

# 右側に伸ばしていく
while 1:
    for i in range(4):
        if ask(res_1+bb_1[i],res_2+bb_2[i]):
            res_1 += bb_1[i]
            res_2 += bb_2[i]
            break
    else:
        break

# 左側に伸ばしていく
while 1:
    for i in range(4):
        if ask(bb_1[i]+res_1,bb_2[i]+res_2):
            res_1 = bb_1[i] + res_1
            res_2 = bb_2[i] + res_2
            break
    else:
        break


Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i=0; i<N ;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int alice=0;
  int bob=0;
  for (int i=0; i<N;i +=2){
  	alice += a.at(i);
  }
  for (int i=1; i<N; i +=2){
  	bob += a.at(i);
  }
  
  cout << alice-bob << endl;
  
}

Measured memory_bytes: 768
#ABC064 A - RGB Cards
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
r,g,b = map(str, input().split())
s = r+g+b
if int(s)%4==0:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

H,W = LI()
s = [input() for _ in range(H)]
dx,dy = [1,0],[0,1]
dp = [[inf]*W for _ in range(H)]


if s[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

h = []
heappush(h, (dp[0][0],0,0))
while h:
    d,y,x = heappop(h)
    for i in range(2):
        nx,ny = x + dx[i], y +dy[i]
        if 0 <= nx < W and 0 <= ny < H:
            if s[ny][nx] == '#' and s[y][x] == '#' and dp[ny][nx] > d:
                dp[ny][nx] = d
                heappush(h,(dp[ny][nx],ny,nx))
            elif s[ny][nx] == '#' and  s[y][x] == '.' and dp[ny][nx] > d+1:
                dp[ny][nx] = d + 1
                heappush(h, (dp[ny][nx],ny,nx))
            elif s[ny][nx] == '.' and dp[ny][nx] > d:
                dp[ny][nx] = d
                heappush(h,(dp[ny][nx],ny,nx))
print(dp[-1][-1])

Measured memory_bytes: 55644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n;
  cin >>n;
  vector<int> h(n);
  for(int i=0;i<n;i++) cin >> h[i];
  
  int ans=0;
  int c=0;
  
  for(int i=1;i<n;i++){
    if(h[i]<=h[i-1]) c++;
    else{
      ans=max(ans,c);
      c=0;
    }
  }
  ans=max(ans,c);
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
int h, w;
vector<string> vec;

int main(int argc, char const* argv[])
{
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    string s;
    cin >> s;
    vec.pb(s);
  }
  set<int> wvec;
  for(int i = 0; i < h; i++){
    bool sh = false;
    for(int j = 0; j < w; j++){
      if(vec[i][j] == '#'){
        sh = true;
        break;
      }
    }
    if(sh)wvec.insert(i);
  }
  set<int> hvec;
  for(int i = 0; i < w; i++){
    bool sh = false;
    for(int j = 0; j < h; j++){
      if(vec[j][i] == '#'){
        sh = true;
        break;
      }
    }
    if(sh)hvec.insert(i);
  }
  for(int i = 0; i < h; i++){
    if(wvec.find(i) == wvec.end())continue;
    for(int j = 0; j < w; j++){
      if(hvec.find(j) == hvec.end())continue;
      cout << vec[i][j];
    }
    cout << endl;
  }
	return 0;
}


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

static const int MAX=200000;
 
int main()
{
    int N[MAX],n;
     
    cin >> n;

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

    int maxv = -2000000000;
    int minv = N[0];
     
    for(int i=1;i<n;i++)
    {
        maxv = max(maxv,N[i] - minv);
         
        minv = min(minv,N[i]);

    }
     
    cout << maxv << endl;
     
    return 0;
}

Measured memory_bytes: 3888
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <set>
#include <queue>
#include <vector>

using namespace std;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int X;
    cin >> X;
    cout << 360 / gcd(X, 360) << endl;
}


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

const int N = 5e5 + 1;
int n, q, fen[N];

struct Query {
	int l, r, idx;
};
bool comp (Query x, Query y) {
	if (x.r == y.r) {
		return x.l < y.l;
	}
	return x.r < y.r;
}
void upd(int i, int val) {

	for (; i <= n; i += i & -i) {
		fen[i] += val;
	}
}
int qry(int i) {

	int sum = 0;
	for (; i > 0; i -= i & -i) {
		sum += fen[i];
	}
	return sum;
}
void solve() {

	cin >> n >> q;
	vector <int> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	vector <Query> qu(q);
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		qu[i].l = a - 1;
		qu[i].r = b - 1;
		qu[i].idx = i;
	}
	sort(qu.begin(), qu.end(), comp);
	vector <int> vis(N, -1), ans(q);
	int qc = 0;
	for (int i = 0; i < n; i++) {
		if (vis[arr[i]] != -1) {
			upd(vis[arr[i]] + 1, -1);
		}
		vis[arr[i]] = i;
		upd(i + 1, 1);
		while (qc < q && qu[qc].r == i) {
			ans[qu[qc].idx] = qry(qu[qc].r + 1) - qry(qu[qc].l);
			qc++;
		}
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
}
signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	// int t;
	// cin >> t;
	// while (t--)
	solve();

	return 0;
}

Measured memory_bytes: 31144
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <time.h>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> Pii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const LL mod = 1000000007;
const int N = 1e5 + 5;
const double Pi = acos(-1.0);
const int maxn = 4e3 + 5;
bool ban[15];
int main() {
#ifdef local
    freopen("in", "r", stdin);
    //  freopen("w","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i = 0 ; i < k; i++){
        int x;
        cin>>x;
        ban[x] = 1;
    }
    for(int i = n ;;i++){
        int x = i;
        bool flag = 0;
        while(x){
            int d = x%10;
            flag |= ban[d];
            x /= 10;
        }
        if(!flag){
            cout<<i<<"\n";
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{long int n,m;
 cin>>n>>m;
 for(long int i=1;i<=m;i++)
 {
     int p;
     cin>>p;
     n-=p;
 }
 cout<<(n>=0?n:-1);

 return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, m;
pair<int,int> A[maxn];
int a[maxn];
int b[maxn];

vector<pair<int,int>> g[maxn];
bool viz[maxn];
vector<int> ans;

void dfs(int at) {
  viz[at]=true;
  for (auto ed: g[at]) {
    int j = ed.first;
    int to = ed.second;
    if (viz[to]) continue;
    dfs(to);
    if (b[to]==1) {
      b[at]^=1;
      ans.push_back(j);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>m;
  for (int i=0; i<n; i++) {
    cin>>A[i].first>>A[i].second;
    a[i] = A[i].first;
  }

  sort(a,a+n);
  sort(A,A+n);
  for (int i=1; i<n; i++) {
    b[i] = A[i].second^A[i-1].second;
  }

  b[0] = A[0].second;
  b[n] = A[n-1].second;

  for (int i=0; i<m; i++) {
    int l,r; cin>>l>>r;
    r = std::upper_bound(a,a+n,r) - a;
    l = std::lower_bound(a,a+n,l) - a;
    g[r].push_back({i,l});
    g[l].push_back({i,r});
  }

  for (int i=0; i<=n; i++) {
    if (!viz[i]) {
      dfs(i);
      if (b[i]==1) out(-1);
    }
  }
  


  sort(ans.begin(), ans.end());
  cout<<ans.size()<<endl;
  for (int x: ans) cout<<x+1<<" ";
  cout<<endl;  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 45564
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

#define p first
#define i second

signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<std::vector<int> > from(n,std::vector<int>());
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		from[a].emplace_back(b);
	}
	std::vector<std::vector<int> >dist(n,std::vector<int>(3,0));
	int s,t;
	std::cin >> s >> t;
	s--;t--;
	std::queue<std::pair<int,int> > que;
	que.emplace(s,0);
	while(!que.empty()) {
		auto c = que.front();
		que.pop();
		if(c.p==t&&c.i==0) {print(dist[c.p][c.i]/3);return 0;}
		for(auto& p:from[c.p]) {
			if(dist[p][(c.i+1)%3])continue;
			dist[p][(c.i+1)%3] = dist[c.p][c.i]+1;
			que.emplace(p,(c.i+1)%3);
		}
	}
	print(-1);
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);

    vector<int> x(n), y(n);
    REP(i, n) {
        cin >> x[i] >> y[i];
    }

    double ans = 0;
    int cnt = 0;

    do {
        double sum = 0;

        REP(i, n-1) {
            int dx = x[p[i + 1]] - x[p[i]], dy = y[p[i + 1]] - y[p[i]];
            sum += sqrt(dx * dx + dy * dy);
        }

        ans += sum;
        cnt++;
    } while(next_permutation(p.begin(), p.end()));

    cout << fixed << setprecision(10) << ans / cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        if (x >= 1 && x <= 100 && y >= 1 && y <= 100) {
            if (x - (y * 2) >= 0) {
                System.out.println(x - (y * 2));
            } else {
                System.out.println(0);
            }
        }
    }
}


Measured memory_bytes: 21844
n = int(input())
a_list = [int(i) for i in input().split()]

minus_count_even_flug = 1
zero_exist_flug = -1

for a in a_list:
    if a < 0:
        minus_count_even_flug *= -1
    if a == 0:
        zero_exist_flug = 1

a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug == 1 or zero_exist_flug == 1:
    print(sum_a_abs_list)
else:
    print(sum_a_abs_list - 2 * min(a_abs_list))


Measured memory_bytes: 14412
#include <iostream>
#include<string>
#include<cctype>
using namespace std;
int main() {
  string str,ab,order;
  char temp;
  int q,a,b;
  cin>>str>>q;
  while(q--){
    cin>>order;
    if(order=="replace"){
      cin>>a>>b>>ab;
      str.replace(a,b-a+1,ab);
    }
    if(order=="reverse"){
      cin>>a>>b;
      for(int i=b,j=a;i>=(b+a+1)/2;i--,j++){
      swap(str[j],str[i]);
      }
    }
    if(order=="print"){
      cin>>a>>b;
      cout<<str.substr(a,b-a+1)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	if (A % 2 == 1 && B % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <complex>
#include <set>
#include <deque>
#define DEBUG(x) cerr<<"line:"<<__LINE__<<", "<<#x" == "<<(x)<<endl;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();it++)
#define fst first
#define snd second
#define ALL(a) a.begin(),a.end()
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define DRI(x) int (x);scanf("%d",&(x))
#define DRII(x,y) int (x),(y);scanf("%d%d",&(x),&(y))
#define DRIII(x,y,z) int (x),(y),(z);scanf("%d%d%d",&(x),&(y),&(z))
#define MS0(a) memset((a),0,sizeof((a)))
#define MS1(a) memset((a),-1,sizeof((a)))
#define MS(a,b) memset((a),(b),sizeof((a)))
using namespace std;

typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

#define INF (int)1e9
#define EPS (1.0e-8)
// ------------------


int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
#endif
    int a, b, c; cin >> a >> b >> c;
    if (a + b + c == 17) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 256
N,D = map(int, input().split())
X = [0 for i in range(0,N)]
Y = [0 for i in range(0,N)]
for i in range(0,N):
    X[i], Y[i] = map(int, input().split())

count = 0   
for i in range(0,N):
    if X[i]**2+Y[i]**2 <= D**2:
        count += 1
        
print(count)

Measured memory_bytes: 24772
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int a, b, k;
  cin >> a >> b >> k;

  int num = 0;
  ROF(i,10000, 1){
    if(a%i == 0 && b%i == 0) num++;
    if(num == k) {
      cout << i << endl;
      break;
    }
    //cout << "i:" << i << " num:" << num << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
// Author : Harshdeep Sharma , IIT Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::min();
const int minimum  = numeric_limits<int>::max();

// function to calculate any numbered power of some number without modulo
ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}
// function to check whether a bracketed sequence is balanced or not
bool isBalanced(const string &exp) {
	// Initialising Variables
	bool flag = true;
	int count = 0;

	// Traversing the Expression
	for (int i = 0; i < exp.length(); i++) {

		if (exp[i] == '(') {
			count++;
		}
		else {
			count--;
		}
		if (count < 0) {
			flag = false;
			break;
		}
	}
	if (count != 0) {
		flag = false;
	}

	return flag;
}
// function to sort by second in a set of pairs
bool sortbysec(const pair<pair<int, int>, int> &a,
               const pair<pair<int, int>, int> &b) {
	return (a.second < b.second);
}

void uniformly_distribute_k_numbers_in_a_square_grid(int n , int k ) {
	int p = 0 , q = 0 ;
	vector<vector<int>> a(n, vector<int>(n)) ;
	for (int i = 1 ; i <= k ; ++i ) {
		a[p][q] = 1 ;
		p = p + 1 ;
		q = (q + 1) % n ;
		if (p == n) {
			p = 0  ;
			q = (q + 1) % n ;

		}
	}
}



// main funtion
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {
	int n , m  , c , prod ;
	cin >> n >> m >> c ;
	vector<int> b(m) ;
	for (int  i = 0  ; i < m ; i++) {
		cin >> b[i] ;
	}
	int ans = 0 ;
	for (int i = 0 ; i < n ; i++) {
		vector<int> a(m) ;
		prod = 0 ;
		for (int i = 0 ; i < m ; i++) {
			cin >> a[i] ;
			prod += b[i] * a[i] ;
			if (i == m - 1) prod += c ;
		}
		if (prod > 0) ans++ ;
	}
	cout << ans << "\n";









	// }







	return 0 ;
}


Measured memory_bytes: 3592
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map> 
#define inf 9999999; 
using namespace std;
 
int n,m,T,i,j,ans,xx,x,yy,y,k;
int a[2005][2005],b[2005][2005],c[2005][2005];
char tu[2005][2005];
int main()
{
	cin>>n>>m>>T;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			cin>>tu[i][j];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	//cout<<1111111<<endl;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
			b[i][j]=b[i][j-1]+b[i-1][j]-b[i-1][j-1];
			c[j][i]=c[j][i-1]+c[j-1][i]-c[j-1][i-1];
			if(tu[i][j]=='1')
				a[i][j]++;
			if(tu[i][j-1]=='1'&&tu[i][j]=='1')
				b[i][j]++;
			if(tu[i-1][j]=='1'&&tu[i][j]=='1')
				c[j][i]++;
 
		//	cout<<"i: "<<i<<" j: "<<j<<" b[i][j]"<<b[i][j]<<endl;
		}
	}
	//cout<<b[n][m]<<endl;
	//cout<<111111111<<endl;
	while(T--)
	{
		cin>>x>>y>>xx>>yy;
		k=a[xx][yy]-a[x-1][yy]+a[x-1][y-1]-a[xx][y-1];
		//cout<<"k "<<k<<endl;
		ans=b[xx][yy]-b[xx][y]-b[x-1][yy]+b[x-1][y];
//		cout<<"ans "<<ans<<endl;
		ans+=c[yy][xx]-c[yy][x]-c[y-1][xx]+c[y-1][x];
		//cout<<"1 :"<<ans<<endl;
		cout<<k-ans<<endl;
	}
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cost;
  edge(int to, int cost):to(to), cost(cost){}
};
using Graph = vector<vector<edge>>;

vint dijkstra(int s, const Graph& g) {
  int n = g.size();
  vint res(n, inf);
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  res[s] = 0;
  que.emplace(0, s);
  while(!que.empty()) {
    Pi p = que.top(); que.pop();
    int v = p.second;
    if(res[v] < p.first) continue;
    for(auto&& e : g[v]) {
      if(res[v]+e.cost < res[e.to]) {
	res[e.to] = res[v]+e.cost;
	que.emplace(res[e.to], e.to);
      }
    }
  }

  return res;
}

#define MAX_N 100010

int ord[MAX_N], low[MAX_N];
void dfs(int u, int p, int k, const Graph& g) {
  ord[u] = low[u] = k++;
  for(auto&& e : g[u]) {
    if(e.to == p) continue;
    if(ord[e.to] == -1) {
      dfs(e.to, u, k, g);
      chmin(low[u], low[e.to]);
    } else {
      chmin(low[u], ord[e.to]);
    }
  }
}
bool is_bridge(int u, int v) {
  if(ord[u] > ord[v]) swap(u, v);
  return ord[u] < low[v];
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  Graph g(n);
  Graph rg(n);
  vint a(m), b(m), c(m);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i], --b[i];
    g[a[i]].emplace_back(b[i], c[i]);
    rg[b[i]].emplace_back(a[i], c[i]);
  }
  vint d0 = dijkstra(0, g);
  vint d1 = dijkstra(1, rg);
  Graph h(n);
  vint used(m, 0);
  rep(i, m) {
    //cout<<d0[a[i]]<<" "<<d1[b[i]]<<" "<<c[i]<<endl;
    if(d0[a[i]]+d1[b[i]]+c[i] == d0[1]) {
      h[a[i]].emplace_back(b[i], 0);
      h[b[i]].emplace_back(a[i], 0);
      used[i] = 1;
    }
  }
  memset(ord, -1, sizeof(ord));
  dfs(0, -1, 0, h);
  rep(i, m) {
    int d = d0[b[i]]+d1[a[i]]+c[i];
    //cout<<d<<" "<<d0[1]<<endl;
    /*
    if(d == d0[1]) {
      cout << "SOSO" << endl;
    } else if(d < d0[1]) {
      cout << "HAPPY" << endl;
    } else if(!used[i]) {
      cout << "SOSO" << endl;
    } else if(is_bridge(a[i], b[i])) {
      cout << "SAD" << endl;
    } else {
      cout << "SOSO" << endl;
    }
    */
    if(used[i]) {
      if(is_bridge(a[i], b[i])) cout << "SAD" << endl;
      else cout << "SOSO" << endl;
    } else {
      if(d < d0[1]) cout << "HAPPY" << endl;
      else cout << "SOSO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 33848
#include<stdio.h>

int main()
{
	int x[4], y[4], x_diff, y_diff; 
	
	scanf("%d %d %d %d", &x[0], &y[0], &x[1], &y[1]);
	
	x_diff = x[1] - x[0];
	y_diff = y[1] - y[0];
	
	x[2] = x[1] - y_diff;
	y[2] = y[1] + x_diff;
	
	x[3] = x[2] - x_diff;
	y[3] = y[2] - y_diff;
	
	printf("%d %d %d %d", x[2], y[2], x[3], y[3]);

	return 0;
}

Measured memory_bytes: 128
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		Arrays.sort(a);
		boolean able = true;
		if (n % 2 > 0) {
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0 && a[i] == i) continue;
				if (i % 2 > 0 && a[i] == i + 1) continue;
				able = false;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0 && a[i] == i + 1) continue;
				if (i % 2 > 0 && a[i] == i) continue;
				able = false;
			}
		}
		if (able) {
			long ans = 1;
			for (int i = 1; i <= n / 2; i++)
				ans = ans * 2 % 1000000007;
			System.out.println(ans);
		}
		else
			System.out.println("0");
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Measured memory_bytes: 58280
from itertools import product
import numpy as np
import sys

# print('input >>')
N, M, X = map(int,(input().split()))

Cs = []

for _ in range(N):
    Cs.append(list(map(int,(input().split()))))

Cs = np.array(Cs)

patterns = product([0, 1], repeat=N)

ans = 10**12

for pattern in patterns:
    # print(pattern)
    for i in range(len(pattern)):
        en = 0
        unds = np.array([0]*M)
        for p in range(len(pattern)):
            if pattern[p] == 1:
                unds += Cs[p, 1:]
                en += Cs[p][0]
                if all([u >= X for u in unds]):
                    # print('p', pattern)
                    ans = min(ans, en)

if ans == 10**12:
    print(-1)
    sys.exit()

# print('-----output-----')
print(ans)

Measured memory_bytes: 27276
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
bool vis[mx];
vector <int> v[mx];

void bfs(int source){
    queue<int> q;
    q.push(source);

    while(!q.empty()){
        int node = q.front();
        q.pop();
        vis[node] = true;

        for(auto i: v[node]){
            if(!vis[i]){
                q.push(i);
                vis[i]=true;
            }
        }
    }

}

int main(){

    int i,total,q;
    scanf("%d%d",&total,&q);

    while(q--){
        int m,n,w;
        scanf("%d%d%d",&m,&n,&w);
        v[m].push_back(n);
        v[n].push_back(m);
    }

    int c=0;
    for(i=1;i<=total;i++){
        if(!vis[i]){
            bfs(i);
            c++;
        }
    }

    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 6648
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

//ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

ll gcd(ll a, ll b)
{
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a%b);
}

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

    ll a, b;

    //cout << gcd(4, 18) << endl;
    //cout << gcd(24, 18) << endl;
    //cout << gcd(17, 1) << endl;

    cin >> a >> b;

    ll _gcd = gcd(a, b);

    //cout << _gcd << endl;

    vector<ll> factors;
    for (ll i=2; i*i<=_gcd; ++i)
    {
        if (_gcd % i)
            continue;
        factors.push_back(i);
        while (_gcd%i == 0)
            _gcd /= i;
    }
    if (_gcd != 1) factors.push_back(_gcd);

    //for(auto i: factors)
    //    cout << i << ' ';
    //cout << endl;

    cout << factors.size() + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            Console.WriteLine(Logic(S));
        }

        private static string Logic(string S)
        {
            var array = S.ToArray();
            var result = (array[2] == array[3]) && (array[4] == array[5]);
            return result ? "Yes" : "No";
        }
    }
}


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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));

int diff(int time1, int time2,int k)
{

	int hourDiff = time2 / 100 - time1 / 100 - 1;
	int minDiff = time2 % 100 + (60 - time1 % 100);

	if (minDiff >= 60) {
		hourDiff++;
		minDiff = minDiff - 60;
	}
	int res=hourDiff*60+minDiff;
	return res-k;
}

// Driver program to test above functions
int main()
{
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	h1*=100;
	h2*=100;
	int time1=h1+m1;
	int time2=h2+m2;
	cout<<diff(time1,time2,k)<<endl;
}




Measured memory_bytes: 3644
modula = 10**9 + 7

def solve(H, W, grid):
  dp = [[0 for _ in range(W + 1)] for _ in range(H + 1)]
  dp[1][1] = 1

  for h in range(1, H + 1):
    for w in range(1, W + 1):
      if grid[h - 1][w - 1] == 0:
        continue

      if h > 1:
        if grid[h - 2][w - 1] == 1:
          dp[h][w] += dp[h - 1][w] % modula
      if w > 1:
        if grid[h - 1][w - 2] == 1:
          dp[h][w] += dp[h][w - 1] % modula

  print(dp[H][W] % modula)

  
def iln(): return list(map(int, input().split()))

  
H, W = iln()
grid = []
for h in range(H):
  grid.append(list(map(lambda i: 1 if i == '.' else 0, input())))
  
solve(H, W, grid)

Measured memory_bytes: 51936
#include<stdio.h>

int main(){
    int a,i,n[101];
    
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&n[i]);
    }
    for(i=a-1;i>=0;i--){
        if(i==a-1)printf("%d",n[i]);
        else printf(" %d",n[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>
#include <string.h>
int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	getchar();

	char str[a+b+1];
	scanf("%s", &str);
	int length = strlen(str);
	int flag = 0;

	
	for(int i=0; i<length; i++)
	{
		if(str[i] >= '0' && str[i] <= '9')
		{
			continue;		//kl ada yg bukan angka, di skip
		}
		else if ('0' > str[i] || str[i] > '9')
		{
			if (i==a) //kalo dia bukan angka tp ternyata di indeks ke a, di okin
			{
				flag = 1;
				continue;
			}
			else if(i !=a)
			{
				flag = 0;
				break;
			}
		}
	}
	
	flag ? printf("Yes\n") : printf("No\n");
	
	return 0;
}

Measured memory_bytes: 1608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.FileStore;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] order;
      StringBuilder result = new StringBuilder(n*4);
      Dictionary dict = new Dictionary(10_000_000);

      for(int i=0; i<n; i++) {
        order = br.readLine().split(" ");
        switch( order[0] ) {
          case "insert" :
            dict.insert(order[1]);
            break;
          case "find" :
            result.append( dict.find(order[1]) ).append("\n");
            break;
        }
      }

      System.out.print(result);
    }
  }
}

class Dictionary {
  boolean[] dict;

  public Dictionary(int size) {
    dict = new boolean[size];
  }

  public void insert(String str) {
    int key   = getKey(str);
    dict[key] = true;
  }
  public String find(String ref) {
    int key = getKey(ref);

    return isExist(key) ? "yes" : "no";
  }
  private int getKey(String str) {
    int len = str.length();
    long ret = 0;

    for(int i=0,d=10; i<len; i++ ) {
      ret = (ret * d) + charToInt(str.charAt(i));
    }
    ret = Long.parseLong(String.valueOf(ret), 5);

    return (int)ret;
  }
  private boolean isExist(int key) {

    return dict[key];
  }
  private int charToInt(char c) {

    switch( c ) {
      case 'A' :
        return 1;
      case 'C' :
        return 2;
      case 'G' :
        return 3;
      case 'T' :
        return 4;
      default :
        return -1;
    }

  }
}


Measured memory_bytes: 176568
N = int(input())
lst = list(map(int, input().split()))
max = 0
cnt = 0
for j in lst:
    if max <= j-1:
        max = j-1
        cnt += 1
    elif max <= j:
        max = j
        cnt += 1
if cnt < N:
    print('No')
else:
    print('Yes')

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

using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;

    vector<long long> vt;
    for (long long i = 1LL; i * i <= M; ++i) {
        if (M % i == 0) {
            if (M >= N * i) vt.push_back(i);
            long long j = M / i;
            if (j != i and M >= N * j) vt.push_back(j);
        }
    }
    sort(vt.begin(), vt.end(), greater<>());

    cout << vt[0] << endl;
    return 0;
}


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

template <class T>
inline void read(T &res)
{
	char ch; bool flag = false; res = 0;
	while (ch = getchar(), !isdigit(ch) && ch != '-');
	ch == '-' ? flag = true : res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
	flag ? res = -res : 0;
}

template <class T>
inline void put(T x)
{
	if (x > 9)
		put(x / 10);
	putchar(x % 10 + 48);
}

template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}
template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}

const int N = 1005;
using std::string;
const string s3[3] = {"a..", "a..", ".bb"};
const string s4[4] = {"aabc", "ddbc", "bcaa", "bcdd"};
const string s5[5] = {"abbaa", "a.ccb", "bc..b", "bc..a", "aabba"};
const string s6[6] = {"aabbcc", "d.d.d.", "d.d.d.", ".d.d.d", ".d.d.d", "aabbcc"};
const string s7[7] = {".aabbcc", "aeef...", "af.f...", "bfee...", "b...eef", "c...f.f", "c...fee"};
char ans[N][N];
int now, n;

inline void solve(int x)
{
	if (x == 3)
	{
		for (int i = 0; i < 3; ++i)
			for (int j = 0; j < 3; ++j)
				ans[now + i][now + j] = s3[i][j];
		now += 3;
	}
	else if (x == 4)
	{
		for (int i = 0; i < 4; ++i)
			for (int j = 0; j < 4; ++j)
				ans[now + i][now + j] = s4[i][j];
		now += 4;
	}
	else if (x == 5)
	{
		for (int i = 0; i < 5; ++i)
			for (int j = 0; j < 5; ++j)
				ans[now + i][now + j] = s5[i][j];
		now += 5;
	}
	else if (x == 6)
	{
		for (int i = 0; i < 6; ++i)
			for (int j = 0; j < 6; ++j)
				ans[now + i][now + j] = s6[i][j];
		now += 6;
	}
	else if (x == 7)
	{
		for (int i = 0; i < 7; ++i)
			for (int j = 0; j < 7; ++j)
				ans[now + i][now + j] = s7[i][j];
		now += 7;
	}
}
int main()
{
	scanf("%d", &n);
	if (n <= 2)
		return puts("-1"), 0;
	int n1 = n >> 3, n2 = n & 7;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			ans[i][j] = '.';
	if (n == 3)
		solve(3);
	else if (n2 >= 4)
	{
		for (int i = 1; i <= n1; ++i)
		{
			solve(4);
			solve(4);
		}
		switch (n2)
		{
			case 3: solve(3); break;
			case 4: solve(4); break;
			case 5: solve(5); break;
			case 6: solve(6); break;
			case 7: solve(7); break;
		}
	}
	else
	{
		for (int i = 1; i < n1; ++i)
		{
			solve(4);
			solve(4);
		}
		n2 += 8;
		switch (n2)
		{
			case 8: solve(4); solve(4); break;
			case 9: solve(4); solve(5); break;
			case 10: solve(5); solve(5); break;
			case 11: solve(5); solve(6); break;
		}
	}
	for (int i = 0; i < n; ++i, putchar('\n'))
		for (int j = 0; j < n; ++j)
			putchar(ans[i][j]);

	return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n;
    string s,t;
    cin>>n>>s>>t;
    REP(i,0,n){
        bool check=true;
        REP(j,0,n-i){
            if(s[j+i]!=t[j]) check=false;
        }
        if(check){
            cout<<n+i<<endl;
            return 0;
        }
    }
    cout<<2*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
int a[MAX_N],b[MAX_N],c[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> a[i+1];
	}

	int M = 0;
	for (int i = N; i > 0; --i)
	{
		if (c[i] != a[i])
		{
			//cout << "a";
			b[i]++;
			M++;
			for (int j = 1; j*j <= i; ++j)
			{
				if (i % j == 0)
				{
					c[j] = (c[j] + 1) % 2;
					if (j * j != i) c[i/j] = (c[i/j] + 1) % 2;
				}
			}
		}
		//cout << i << "  "; 
		//rep(i,N) cout << c[i+1] << " ";
		//cout << endl; 
	}
	cout << M << endl;
	int cnt = 0;
	rep(i,N)
	{
		if (b[i+1])
		{
			if (cnt != 0) cout << " ";
			cout << i+1;
			cnt++;
		}
	}
	if (cnt != 0) cout << endl;
	return 0;
}

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

int main()
{
	int n; cin >> n;
	bool res = false;
	for (int i = 0; i * 4 <= n; i++) {
		for (int j = 0; j * 7 <= (n - i * 4); j++) {
			if (n == i * 4 + j * 7) {
				res = true;
			}
		}
	}
	if (res) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  /*
  vector<int> A(N, 0);
  vector<vector<int>> A(H, vector<int>(W));
  pair<int, string> P[N];
  pair<int, string> P{1, "a"};
  tuple<int, string, bool> A[N];
  tuple<int, string, bool> A{1, "a", true};
  map<string, int> A[N];
  map<char, int> A{{'a', 1}, {'b', 2}};
  array<int, 3> A{1, 2, 3};
  int A[10]{};
  */
 
  int N;
  cin >> N;
  string S;
  cin >> S;

  int l = S.size();
  map<char, int> dic{};
  string s2;
  int ans = 0;
  rep(i, 1, l) {
    s2 = S.substr(i);
    rep(j, 0, i) {
      if (s2.find(S[j]) != string::npos) {
        dic[S[j]] = 1;
      }
    }
    ans = max(ans, int(dic.size()));
    dic.clear();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;
    
    cin >> n;
    for (int i=0; i<n; i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for (int i=1; i<n; i++){
        maxv = max(maxv, R[i]-minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;

}



Measured memory_bytes: 3864
h, w, d = gets.split.map(&:to_i)
numbers = Array.new(h * w) { Array.new }
h.times do |h_index|
  row = gets.split.map(&:to_i)
  row.each_with_index do |num, w_index|
    numbers[num - 1].push(h_index, w_index, 0)
  end
end
q = gets.to_i
questions = []
q.times { questions << gets.split.map(&:to_i).map(&:pred) }

(0...d).each do |start|
  cost = 0
  current = start
  start.step(h * w - 1, d) do |spot|
    cost += (numbers[current][0] - numbers[spot][0]).abs + (numbers[current][1] - numbers[spot][1]).abs
    numbers[spot][3] = cost
    current = spot
  end
end

questions.each do |start, goal|
  puts numbers[goal][3] - numbers[start][3]
end


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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	a[0] = 1;
	for (int i = 1; i < n; i++) a[i] = a[i - 1] + n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}

	vector<int> b(n);
	b[n - 1] = 1;
	for (int i = n - 2; i >= 0; i--) b[i] = b[i + 1] + n;

	for (int i = 0; i < n; i++) {
		b[p[i]] += i;
	}

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

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

Measured memory_bytes: 896
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        x1: i16,
        y1: i16,
        x2: i16,
        y2: i16,
    }

    // let vx = x2 - x1;
    // let vy = y2 - y1;
    // println!("{} {} {} {}", x2-vy, y2+vx, x1-vy, y1+vx);
    println!("{} {} {} {}", y1+x2-y2, -x1+x2+y2, x1+y1-y2, y1-x1+x2);
}


Measured memory_bytes: 2168
import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;
public class Main {
	public static void merge(long arr[], int l, int m, int r) 
    { 
        // Find sizes of two subarrays to be merged 
        int n1 = m - l + 1; 
        int n2 = r - m; 
  
        /* Create temp arrays */
        long L[] = new long [n1]; 
        long R[] = new long [n2]; 
  
        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
  
  
        /* Merge the temp arrays */
  
        // Initial indexes of first and second subarrays 
        int i = 0, j = 0; 
  
        // Initial index of merged subarry array 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
  
        /* Copy remaining elements of L[] if any */
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
  
        /* Copy remaining elements of R[] if any */
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
	 public static void sort(long arr[], int l, int r) 
	    { 
	        if (l < r) 
	        { 
	            // Find the middle point 
	            int m = (l+r)/2; 
	  
	            // Sort first and second halves 
	            sort(arr, l, m); 
	            sort(arr , m+1, r); 
	  
	            // Merge the sorted halves 
	            merge(arr, l, m, r); 
	        } 
	    } 
	 private static int gcd(int n, int l) {
	        if (l == 0)
	            return n;
	        return gcd(l, n % l);
	    }
	public static void main(String[] args) throws Exception
	{
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int a=Integer.parseInt(s.substring(0, 2));
		int b=Integer.parseInt(s.substring(2,4));
	    if(a>0 && a<=12 && b>0 && b<=12)
			System.out.println("AMBIGUOUS");
	    else if(a>0 && a<=12 )
			System.out.println("MMYY");
		else if(b>0 && b<=12 )
			System.out.println("YYMM");
		else
			System.out.println("NA");
	}
}


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

int main()
{
  int K;
  cin >> K;
  
  vector<ll> A;
  for (int i = 1; i <= 9; i++)
  {
    A.push_back(i);
  }
  
  while (1)
  {
    if (K <= A.size())
    {
      cout << A[K - 1] << endl;
      
      return 0;
    }
    
    K -= A.size();
    
    vector<ll> old_num;
    swap(old_num, A);
    
    for (ll x : old_num)
    {
      for (int i = -1; i <= 1; i++)
      {
        int tmp_num = x % 10 + i;
        
        if (0 > tmp_num || 9 < tmp_num)
        {
          continue;
        }
        
        ll new_num = x * 10 + tmp_num;
        
        A.push_back(new_num);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,x,y;
	cin>>n>>x>>y;
	x--,y--;
	vector<int> edges[2000];
	for (int i=0;i<n-1;i++){
		edges[i].push_back(i+1);
		edges[i+1].push_back(i);
	}
	edges[x].push_back(y);
	edges[y].push_back(x);
	
	vector<int> ans(n);
	for (int s=0;s<n;s++){
		vector<int> dist(n,1e9);
		queue<int> q;
		dist[s]=0;
		q.push(s);
		while (q.size()){
			int i=q.front();
			q.pop();
			for (int j : edges[i])
				if (dist[j]==1e9){
					dist[j]=dist[i]+1;
					q.push(j);
				}
		}
		for (int i=s+1;i<n;i++) ans[dist[i]]++;
	}
	for (int i=1;i<n;i++) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 384
fun main(){

    val n = readLine()!!.toInt()

    var list = readLine()!!.split(" ").map(String::toLong).toMutableList()

    var cnt = 0L

    for (i in 0..list.size-2){
        if (list[i]>list[i+1]){
            cnt += list[i] - list[i+1]
            list[i+1] = list[i]
        }
    }

    println(cnt)
}

Measured memory_bytes: 64648