akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int main(){
    int A, B, Q;
    std::cin >> A >> B >> Q;
    std::vector< long long > S(A);
    std::vector< long long > T(B);
    std::vector< long long > X(Q);
    for(int i=0; i<A; i++){
        std::cin >> S[i];
    }
    for(int i=0; i<B; i++){
        std::cin >> T[i];
    }
    for(int i=0; i<Q; i++){
        std::cin >> X[i];
    }
    
    for(int i=0; i<Q; i++){
        int leftS = 0;
        int rightS = A;
        if(A == 1){
            rightS = 0;
        }else{
            while(!(leftS == rightS-1)){
                int mid = (rightS + leftS) / 2;
                if(S[mid] > X[i]){
                    rightS = mid;
                }else{
                    leftS = mid;
                }
            }
        }
        if(rightS == A){
            rightS -= 1;
        }
        //std::cout<<"a"<<leftS<<" "<<rightS<<std::endl; 
        
        int leftT = 0;
        int rightT = B;
        if(B == 1){
            rightT = 0;
        }else{
            while(!(leftT == rightT-1)){
                int mid = (rightT + leftT) / 2;
                if(T[mid] > X[i]){
                    rightT = mid;
                }else{
                    leftT = mid;
                }
            }
        }
        if(rightT == B){
            rightT -= 1;
        }
        
        std::vector< long long > dist(8);
        dist[0] = std::abs(S[leftS] - X[i]) + std::abs(S[leftS] - T[leftT]);
        dist[1] = std::abs(S[leftS] - X[i]) + std::abs(S[leftS] - T[rightT]);
        dist[2] = std::abs(S[rightS] - X[i]) + std::abs(S[rightS] - T[leftT]);
        dist[3] = std::abs(S[rightS] - X[i]) + std::abs(S[rightS] - T[rightT]);
        dist[4] = std::abs(T[leftT] - X[i]) + std::abs(T[leftT] - S[leftS]);
        dist[5] = std::abs(T[leftT] - X[i]) + std::abs(T[leftT] - S[rightS]);
        dist[6] = std::abs(T[rightT] - X[i]) + std::abs(T[rightT] - S[leftS]);
        dist[7] = std::abs(T[rightT] - X[i]) + std::abs(T[rightT] - S[rightS]);
        std::sort(dist.begin(), dist.end());
        std::cout << dist[0] << std::endl;
    }
    
    
    return 0;
    
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m, vector<int>(n));
    vector<int> k(m);
    vector<int> p(m);
    vector<int> ab{1, 2, 3, 4, 5};

    for (int i = 0; i < m; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }

    int num = 0;
    //スイッチのon-offパターン
    for (int i = 0; i < (1 << n); ++i) {
        //電球が点灯するか
        for (int j = 0; j < m; ++j) {
            int tmp = 0;
            for (int l = 0; l < k[j]; ++l) {
                if(i & (1<<(s[j][l]-1))) {
                    tmp++;
                }
            }
            if(tmp % 2 != p[j]){
                break;
            }
            else if(j == m-1 && tmp % 2 == p[j]){
                num++;
            }
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int f[505][505];

int main(){
    /*int n;
    scanf("%d",&n);
    for(int s = 0; s <= n; s++){
        for(int i = 0; i <= s; i++){
            int j = s-i;
            if(i<=1 && j<=1) f[i][j] = 0;
            else{
                for(int take = 2; take <= i; take += 2){
                    int li = i-take, lj = j+take/2;
                    if(f[li][lj]==0) f[i][j] = 1;
                }
                for(int take = 2; take <= j; take += 2){
                    int li = i+take/2, lj = j-take;
                    if(f[li][lj]==0) f[i][j] = 1;
                }
            }
            //printf("f[%d][%d] = %d\n",i,j,f[i][j]);
        }
    }
    for(int i = 0; i <= n; i++){
        for(int j = i; j <= n-i; j++){
            printf("f[%d][%d] = %d\n",i,j,f[i][j]);
        }
    }*/
    long long x,y;
    scanf("%lld%lld",&x,&y);
    if(x>y){
        long long t = x;
        x = y;
        y = t;
    }
    if(x==y || (x+1)==y) printf("Brown\n");
    else printf("Alice\n");
    return 0;
}


Measured memory_bytes: 1644
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,a,b) for(int (i)=(a);(i)<(b);i++)
int h, w,c;
int max_n = 0;
struct Area{ int c, f; };
Area area[8][8] = { 0 };
typedef pair <int,int>P;

void solve(int cr, int level){

	queue<P> que;
	bool color[6] = { false };
	color[c] = true;
	bool check[8][8] = { false };
	que.push(P(0, 0));
	while (!que.empty()){
		P pos = que.front();
		que.pop();
		int y = pos.first;
		int x = pos.second;
		area[y][x].f++;
		if (y > 0)if (!check[y - 1][x]){
			if (area[y - 1][x].c == cr)que.push(P(y - 1, x));
			else color[area[y - 1][x].c] = true;
			check[y - 1][x] = true;
		}
		if (x > 0)if (!check[y][x - 1]){
			if (area[y][x - 1].c == cr)que.push(P(y, x - 1));
			else color[area[y][x - 1].c] = true;
			check[y][x - 1] = true;
		}
		if (y < h - 1)if (!check[y + 1][x]){
			if (area[y + 1][x].c == cr)que.push(P(y + 1, x));
			else color[area[y + 1][x].c] = true;
			check[y + 1][x] = true;
		}
		if (x < w - 1)if (!check[y][x + 1]){
			if (area[y][x + 1].c == cr)que.push(P(y, x + 1));
			else color[area[y][x + 1].c] = true;
			check[y][x + 1] = true;
		}
	}
	
	if (level<5){
		rep(k, 0, 6)if (color[k]){
			rep(i, 0, h)rep(j, 0, w)if (area[i][j].f>0)area[i][j].c = k;
			solve(k, level + 1);
		}
	}
	if (cr == c){
		int n = 0;
		rep(i, 0, h)rep(j, 0, w)if (area[i][j].f > 0)n++;
		if (max_n<n)max_n = n;
	}
	rep(i, 0, h)rep(j, 0, w)if (area[i][j].f>0)area[i][j].c = cr, area[i][j].f--;
		
	
}

int main(void){
	while (true){
		cin >> h >> w >> c;
		if (h == 0)
		return(0);
		c--;
		max_n = 0;
		//input
		rep(i, 0, h)rep(j, 0, w){
			Area input;
			cin >> input.c;
			input.c--;
			input.f = 0;
			area[i][j] = input;

		}
		solve(area[0][0].c, 0);
		cout << max_n << endl;
	}
}

Measured memory_bytes: 1204
h, w = map(int, input().split())
A = [input() for i in range(h)]

def dfs(i, j):
    if(i == h-1 and j == w-1):
        return 'Possible'
    if(i < h-1 and A[i+1][j] == '#'):
        return dfs(i+1, j)
    if(j < w-1 and A[i][j+1] == '#'):
        return dfs(i, j+1)
    return 'Impossible'

if sum([a.count('#') for a in A]) != (h+w-1):
    print('Impossible')
else:
    print(dfs(0, 0))


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s.size() == 1) {
		cout << "No" << endl;
	}
	else {
		int flag = 0;
		while (1) {
			string tmp = s;
			vi cnt(3, 0);
			REP(i, tmp.size()) {
				cnt[tmp[i] - 'A']++;
			}
			char c = min_element(ALL(cnt))-cnt.begin() + 'A';
			int b = 0;
			REP(i, 3)if (cnt[i] == *min_element(ALL(cnt)))b++;
			if (b != 1)break;
			for (int i = 0; i + 2 < tmp.size(); ++i) {
				if (tmp.substr(i, 3) == "ABC") {
					tmp[i] = c;
					tmp.erase(tmp.begin() + i + 1);
					tmp.erase(tmp.begin() + i + 1);
				}
			}
			if (s == tmp)break;
			s = tmp;
		}
		if (s!="ABC")cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}

Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
	int n ,d,q;

	cin >> n >> d;
	q = n % (d * 2 + 1);

		if (q == 0)
			cout << n / (d * 2 + 1) << endl;
		else
			cout << (n / (d * 2 + 1) + 1)<< endl;
	
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  vector<ll> p(5);
  ll m = INFL;

  rep(i,5){
    cin >> p.at(i);
    m = min(m,p.at(i));
  }

  cout << (n-1)/m + 5 << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
  int x, y;
  cin >> x >> y;
  if(x == 1 && y == 1)
  {
    cout << 1000000 << endl;
    return 0;
  }
  int ans = 0;
  if(x == 1) ans += 300000;
  else if(x == 2) ans += 200000;
  else if(x == 3) ans += 100000;
  if(y == 1) ans += 300000;
  else if(y == 2) ans += 200000;
  else if(y == 3) ans += 100000;
  cout << ans << endl;
}

Measured memory_bytes: 256
class Main
  def execute
    @s = gets.chomp.chars
    @p = ""
    @h = ""
    @count = 0
    @s.each do |w|
      @h += w
      if @p == @h
        @p = @h
      else
        @p = @h
        @h = ""
        @count += 1
      end
    end
    puts @count
  end
end
Main.new.execute

Measured memory_bytes: 16764
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)

int main()
{
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL);cout.tie(NULL);
 
 string s;cin>>s;
 if(s=="ABC" )
 cout<<"ARC"<<endl;
 if(s=="ARC")
 cout<<"ABC"<<endl;
  
 
}

Measured memory_bytes: 3628
program main
   integer, allocatable :: s(:, :, :)
   read(*, *)ia, jb, kc, ix
   allocate(s(0:ia, 0:jb, 0:kc))
   forall(i=0:ia, j=0:jb, k=0:kc) s(i, j, k) = i*500 + j*100 + k*50
   write(*, *) count(s == ix)
   deallocate(s)
end

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
const int M = 1e6+5;
string s;
int nxt[M],pre[M],tot,q,t,head,tail,flag,f;
char val[M];
void init(){
    head = ++tot, tail = ++tot;
    nxt[head] = tail, pre[tail] = head;
}
void addh(char c){
    int q = ++tot;
    pre[nxt[head]] = q; nxt[q] = nxt[head]; 
    pre[q] = head; nxt[head] = q;
    val[q] = c;
}
void addt(char c){
    int q = ++tot;
    nxt[pre[tail]] = q; pre[q] = pre[tail]; 
    nxt[q] = tail; pre[tail] = q;
    val[q] = c;
}
void printh(){
    for(int i = nxt[head]; i != tail; i = nxt[i])cout << val[i];
}
void printt(){
    for(int i = pre[tail]; i != head; i = pre[i])cout << val[i];
}
int main(){
    cin >> s >> q;
    for(int i = 0; i < s.length(); i++)addt(s[i]);
    for(int i = 1; i <= q; i++){
        cin >> t;
        if(t == 1)flag++, flag &= 1;
        else{
            cin >> f >> s;
            f &= 1;
            if((f^flag) == 1)addh(s[0]);
            else addt(s[0]);
        }
    }
    if(!flag)printh();
    else printt();
    return 0;
}


Measured memory_bytes: 6272
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();

		String regex = "^[0-9]{" + a + "}-[0-9]{" + b + "}$";
		if (s.matches(regex)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21972
#include<cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	if(n<1200)printf("ABC\n");
	if(n>=1200&&n<2800)printf("ARC\n");
	if(n>=2800)printf("AGC\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner( System.in);
		int a=kb.nextInt();
		int b=kb.nextInt();
		int c=kb.nextInt();
		
		if( a < b ) {
			if( b < c ) {
				System.out.println( "Yes");		
			} else {
				System.out.println( "No");	
			}
		} else {
			System.out.println( "No");		
		}
	}
}

Measured memory_bytes: 17164
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll A;
    cin >> A;
    ll V;
    cin >> V;
    ll B;
    cin >> B;
    ll W;
    cin >> W;
    ll T;
    cin >> T;
    ll dist=llabs(A-B);
    if((V-W)*T>=dist){prt("YES")}
    else prt("NO")

    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();

		if (C <= (A + B)) {
			System.out.print("Yes");
		} else {
			System.out.print("No");
		}

	}

}


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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

void dfs(int i,vector<vector<int>>& a,vector<int>& depth) {
    for (int j : a[i]) dfs(j,a,depth);
    vector<int> b;
    for (int j : a[i]) b.push_back(depth[j]);
    sort(b.begin(),b.end(),greater<int>());
    for (int j = 0;j < a[i].size();++j) depth[i] = max(depth[i],b[j]+j+1);
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n);
    vector<int> depth(n,0);
    for (int i = 1;i < n;++i) {
        int b;
        cin >> b;
        b--;
        a[b].push_back(i);
    }
    //for (int i = 0;i < n;++i) p_ary(a[i],0,a[i].size(),j);
    dfs(0,a,depth);
    //p_ary(depth,0,n,i);
    cout << depth[0] << endl;
    return 0;
}

Measured memory_bytes: 17024
#include <stdio.h>

main(){
  int s1, s2, i, a, max=0;

  while(1){
max=0;
    for(i=0;i<5;i++){
      scanf("%d %d", &s1, &s2);
      if(s1==0 && s2==0) break;
      if(max<s1+s2){
	max = s1+s2;
	a = i;
      }
    }
    if(s1==0 && s2==0) break;

    switch(a) {
    case 0:
      printf("A ");
      break;
    case 1:
      printf("B ");
      break;
    case 2:
      printf("C ");
      break;
    case 3:
      printf("D ");
      break;
    case 4:
      printf("E ");
      break;
    }

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  rep(i, m) { cin >> s[i] >> c[i]; }
  for (int i = 0; i < pow(10, n); i++) {
    string str = to_string(i);
    bool flag = true;
    rep(j, m) {
      if (str[s[j] - 1] != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag && str.length() == n) {
      cout << str << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}


Measured memory_bytes: 3968
#include <stdio.h>
#include <stdlib.h>
#define ll long long
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int main(){
  ll n,L,T;
  ll ans[100010];
  scanf("%lld%lld%lld",&n,&L,&T);
  ll cnt=0,i;
  for(i=0;i<n;i++){
    ll x,w;
    scanf("%lld%lld",&x,&w);
    (w==1)?(x+=T):(x-=T);
    cnt-=x/L;
    x%=L;
    if(x<0){
      x+=L;
      cnt++;
    }
    ans[i]=x;
    cnt%=n;
  }
  qsort(ans,n,sizeof(ll),upll);
  for(i=0;i<n;i++)printf("%lld\n",ans[(i-cnt+n)%n]);
}

Measured memory_bytes: 1900
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		
	    if(k==1)
	    System.out.println("0");
	    else
	    System.out.println(n-k);
		
	}
}

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

int main(){
    int n,m,c;
    cin>>n>>m>>c;
    int s=c,t=0;
    vector<int> b(m),v(m);
    for(int i=0;i<m;i++) cin>>b[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>v[j];
            s+=v[j]*b[j];
        }
        if(s>0) t++;
        s=c;
    }
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<string>s;
int h,w;
int dx[] = {-1,0,0,1};
int dy[] = {0,-1,1,0};
bool isrange(int x,int y){
    return 0<=x and x < h and 0<= y and y < w;
}
int a,b;
bool used[400][400];
void dfs(int x,int y){
    if(s[x][y] == '.')a++;
    else b++;
    used[x][y] = true;
    rep(i,4){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if(isrange(xx,yy) and !used[xx][yy] and s[x][y] != s[xx][yy]){
            dfs(xx,yy);
        }
    }
}
int main(){
    cin >> h >> w;
    s.resize(h);
    rep(i,h)cin >> s[i];
    ll ans = 0;
    rep(i,h)rep(j,w){
        if(!used[i][j]){
            a = b = 0;
            dfs(i,j);
            ans += (ll)a*b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
//s.find_by_order(index) returns iterator to the index-th element
//in O(logn) time.



typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<string> vss;
typedef vector<pair<ll, ll> > vpll;
typedef unordered_map<ll ,ll> mpll;
typedef unordered_map<int ,int> mpii;
typedef unordered_map<char ,ll> mpcl;
typedef pair<ll , ll> pll;
typedef complex<double> cd;
typedef vector< complex<double> > vcd;


#define fore(i,n) for(i=0;i<n;i++)
#define forz(i,s,f) for(i=s;i<f;i++)
#define forer(i,n) for(i=n-1;i>=0;i--)
#define forzr(i,s,f) for(i=s;i>=f;i--)
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define pvec(i,vec) fore(i,vec.size())cout<<vec[i]<<" ";cout<<"\n";

const ll mod=1e9+7;
const ll modulo=998244353;
const double pi = 3.14159265358979323846;


ll power(ll x,ll y,ll m)//gives (x^y)%m
{
    ll ans=1;
    while (y>0)
    {
        if(y & 1)
        {
            ans=(ans*x)%m;
        }
        y=y/2;
        x=(x*x)%m;
    }
    return ans;
}

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

ll lcm(ll a,ll b)
{
	ll ans=(a*b)/gcd(a,b);
	return ans;
}

long double logn(long double a,long double n)
{
	return(log(n)/log(a));
}

bool sortbysec(pll &a,pll &b)
{
    return(a.ss<b.ss);
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);

	ll te=1,test,i,j,n,m,flag,k,p,temp;
	//cin>>te;
	
	for(test=1;test<=te;test++)
	{
		cin>>n;
		
		vll a(n);
		fore(i,n)
		{
			cin>>a[i];
		}

		ll ans=0;
		temp=a[0];
		forz(i,1,n)
		{
			if(temp>a[i])
			{
				ans+=(temp-a[i]);
			}
			temp=max(temp,a[i]);
		}

		cout<<ans<<"\n";
		//cout<<"hello\n";
		//cout<<"Case #"<<test<<": ";
	}

	return 0;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll taro(int arr[][3],int n){
      
      ll dp[n][3];
       dp[0][0] = arr[0][0];
       dp[0][1] = arr[0][1];
       dp[0][2] = arr[0][2];
      for(int i=1; i<n; i++){ 
        for(int j=0; j<3; j++){
            if(j == 1){
                dp[i][j] = max(dp[i-1][j-1] ,dp[i-1][j+1])+arr[i][j];
            }
            else{
                int l = abs(j-1);
                int r = abs(j-2);
                dp[i][j] = max(dp[i-1][l],dp[i-1][r]) + arr[i][j];
            }
        }
      }

   return max(dp[n-1][2],max(dp[n-1][0],dp[n-1][1]));

}
int main() {
     int n;
     cin >> n;
     int arr[n][3];
     for(int i=0; i<n; i++){
         for(int j=0; j<3; j++)
            cin >> arr[i][j];
     }
     cout << taro(arr,n);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int m=1;
    while(n/m){
        m<<=1;
    }
    cout<<m/2<<endl;
    return 0;
}


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

int main(){
  int N, X, T;
  cin >> N >> X >> T;
  
  if (N<=X) {
    cout << T << endl;
  }
  else {
    bool t=true;
    int count = 1;
    
    while((N-X)>0){
        ++count;
        N=N-X;
    }
    cout << T*count << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  ll k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'a') continue;
    int t = 'z' + 1 - s[i];
    if (t > k) continue;
    s[i] = 'a';
    k -= t;
  }
  s[n - 1] = (s[n - 1] - 'a' + k) % 26 + 'a';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())

void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}

void test_case(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    if(n>=3200){test(s);}
    else{
        test("red");
    }
}

int main(){
    fastio;
    file();
    int T=1;
    //int T;
    //cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner  yomi = new Scanner(System.in);
        int[] n = new int[yomi.nextInt()];
        int k = yomi.nextInt();
        for (int i=0;i<n.length;i++){
            n[i] = yomi.nextInt();
        }
        Arrays.sort(n);
        int goukei = 0;
        for (int i=0;i<k;i++){
            goukei += n[i];
        }
        System.out.println(goukei);
        }

}

Measured memory_bytes: 38908
package main

import (
  "fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	t := make([]int, n)
	for i := range t {
		fmt.Scan(&t[i])
	}

	for _, v := range t {
		if v % 2 == 0 {
			if v % 3 == 0 || v % 5 == 0 {
				continue
			}
			fmt.Println("DENIED")
			return
		}
	}

	fmt.Println("APPROVED")
}

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

using ll = long long;

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

    ll x;cin>>x;

    ll ans=0;

    ans=(x/500)*1000;

    x=x%500;

    ans+=(x/5)*5;

    cout<<ans<<"\n";

    return 0;
}


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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
        return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/

int main()
{
    ll l , r , mn = INT_MAX;

    cin >> l >> r;

    if((r - l) >= 2019){
        cout << 0 << "\n";
        return 0;
    }

    for(ll i = l; i < r; ++i){
        for(ll j = l+1; j <= r; ++j){
            mn = min(mn , ((i*j)%2019));
        }
    }

    cout << mn << "\n";

    return 0;
}


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

int main(void){
	int N,a,f=0;
	cin>>N;
	map<int,bool> color;
	rep(i,N){
		cin>>a;
		if(a>=3200)f++;
		else color[a/400]=true;
	}
	int C=color.size();
	cout<<max(C,1)<<" "<<C+f<<endl;
	return 0;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int O, s, U, P;
	O = a+b+c;
	s = O/2;
	U = s*(s-a)*(s-b)*(s-c);
	P = sqrt(U);
	cout << P;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (x, y) = {
        let v: Vec<u64> = read();
        (v[0], v[1])
    };

    let mut z = y / x;
    let mut ans = 0;
    while z != 0 {
        z = z >> 1;
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VI P(N);
    VI dp(N+1,0);
    REP(i,N)
    {
        cin >> P[i];
    }
    REP(i,N){
        dp[P[i]] = max(dp[P[i]-1]+1, dp[P[i]]);
    }
    int longest = 0;
    REP(i,N+1){
        if(dp[i] > longest)  longest = dp[i];
    }
    cout << N - longest << endl;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;

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

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

int main(void) {
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (ll i = 0;i < n;i++)cin >> a[i];
	ll ans = a[0];
	for (ll i = 1;i < n;i++)ans = gcd(ans, a[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int num1 = scanner.nextInt();
        int num2 = scanner.nextInt();
        int area = num1 * num2;
        int around = 2 * (num1 + num2);
        System.out.println(area + " " + around);   
        scanner.close();
    }
}


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

long long mod = 1e9+7;
//

int main(){
  long long w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << w * h * 1.0 / 2 << " " << ((x*2 == w && y*2 == h)?1:0) << endl;

  return 0;
}





Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int size; 
    scanf("%d",&size);
    
    int i;
    int document[size];
    
    for (i = 0; i < size; i++) {
        scanf("%d",&document[i]);
    }
    
    for (i = 0; i < size; i++) {
        if (document[i]%2 == 0) {
            if ((document[i]%3 != 0) && (document[i]%5 != 0)) {
                printf("DENIED");
                return 0;
            }
        }
    }
    printf("APPROVED");
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#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=n-1;i<=0;--i)
#define loop        while(true)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const ll MAX = 10000000;
const ll MIN = 0;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using pint = pair<int, int>;
using pstring = pair<int, string>;

int main() {
    ll N; cin >> N;
    if(N % 2 == 0 || N % 5 == 0) { 
        cout << -1 << endl;
        return 0;
    }
    ll ans = 1;
    ll mod = 7 % N;

    while(mod%N) {
        mod *=  10;
        mod += 7;
        mod %= N;
        ans++;
    }

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


Measured memory_bytes: 3608
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    n, k = MI()
    A = LI()
    sm = sum(A)

    div = []
    for i in range(1, int(pow(sm, 0.5))+1):
        if sm % i: continue
        div.append(i)
        if i != sm //i:
            div.append(sm // i)
    ans = 1
    for d in div:
        R = [a % d for a in A]
        R.sort()
        plus = 0
        minus = 0
        for r in R:
            plus += d - r
        for r in R:
            minus += r
            plus -= d - r
            if minus == plus and plus <= k:
                ans = max(ans, d)
    print(ans)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 3428
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] T = new int[5];
            int[] R = new int[5];
            int Total = 0;

            for (int i = 0; i < 5; i++)
            {
                T[i] = int.Parse(Console.ReadLine());
                R[i] = (T[i] - 1) % 10 + 1;
                Total += (T[i] - 1) / 10 + 1;
            }

            Array.Sort(R);

            Total = (Total - 1) * 10 + R[0];


            Console.WriteLine(Total.ToString());
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; double cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}


int maxpow(int a) {
   int res = 1;
   while (res <= a) res *= 2;
   return res;
}

signed main()
{
   int N; cin >> N;
   vec<int> A(N);
   REP(i, 0, N) {
      cin >> A[i];
   }

   map<int,int> m;
   REP(i, 0, N) {
      m[A[i]]++;
   }

   UNIQUE(A);
   RSORT(A);

   int ans = 0;
   REP(i, 0, SZ(A)) {
      if (m[A[i]] > 0) {
         int M = maxpow(A[i]);
         if (M != 2*A[i]) {
            while (m[A[i]] > 0 && m[M - A[i]] > 0) {
               m[A[i]]--;
               m[M - A[i]]--;
               ans++;
            }
         } else {
            while (m[A[i]] > 1) {
               m[A[i]] -= 2;
               ans++;
            }
         }
      }
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 26752
#include <stdio.h>

int main(void){
    int a,b;
    int k;
    scanf("%d %d %d",&a,&b,&k);
    if((b-a) >= 2*k){
        for(int i=a; i<k+a;i++) printf("%d\n",i);
        for(int i=b-k+1; i<b+1; i++) printf("%d\n",i);
	}else{
        for(int i=a; i<=b;i++) printf("%d\n",i);
	}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const ll INF = 1e9;

int W[101];
int V[101];
ll dp[101][1000001] = {0};
ll sumW[101][1000001] = {0};


int main() {
    int N, limW; cin >> N >> limW;

    REP(i, N) {
        cin >> W[i] >> V[i];
    }

    REP(i, N) {
        REP(sumW, limW+1) {
            ll score = dp[i][sumW];
            if (sumW >= W[i]) { // pickup this item
                chmax(score, dp[i][sumW-W[i]] + V[i]);

            // } else { // not pickup
            //     chmax(score, dp[i][sumW]);
            }
            dp[i+1][sumW] = score;
        }
    }

    // REP(i, N+1) {
    //     REP(w, limW+1) {
    //         cout << dp[i][w] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[N][limW] << endl;

    return 0;
}

Measured memory_bytes: 286976
#include<iostream>
using namespace std;
string s[1002];
int n,m;
string t[2];
int d(int x,int y)
{
	return s[x][y]==t[0][0]&&s[x+1][y]==t[1][0]&&s[x][y+1]==t[0][1]&&s[x+1][y+1]==t[1][1];
}
int c(int x,int y)
{
	return d(x-1,y-1)+d(x-1,y)+d(x,y-1)+d(x,y);
}
main()
{
	cin>>n>>m;
	s[0].resize(m+2);s[n+1].resize(m+2);
	for(int i=0;i<n;i++)
	{
		cin>>s[i+1];
		s[i+1]=" "+s[i+1]+" ";
	}
	cin>>t[0]>>t[1];
	int sum=0;
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)sum+=d(i,j);
	}
	int M=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char sto=s[i][j];
			if(sto!='J')s[i][j]='J',M=max(M,c(i,j));
			if(sto!='O')s[i][j]='O',M=max(M,c(i,j));
			if(sto!='I')s[i][j]='I',M=max(M,c(i,j));
			s[i][j]=sto;
		}
	}
	cout<<sum+M<<endl;
}

Measured memory_bytes: 5076
<?php
fscanf(STDIN, "%d %d %d %d", $q, $h, $s, $d);
fscanf(STDIN, "%d", $n);
$m1 = min($q * 4, $h * 2, $s);
$m2 = min($m1 * 2, $d);
echo (int) ($n / 2) * $m2 + ($n % 2) * $m1;

Measured memory_bytes: 4856
#include<iostream>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int main(){
	int n,sum=0;
	cin>>n;
	vector<int>l(n),r(n);
	for(int i=0;i<n;i++){
		cin>>l[i];
		cin>>r[i];
	}
	for(int i=0;i<n;i++){
		sum+=(r[i]-l[i]+1);
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 128
N, M = map(int, input().split())
es = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, used):
    global cnt
    used[v] = 1
    if all(used):
        cnt+=1
    for nv in es[v]:
        if used[nv]:
            continue
        dfs(nv, used)
    used[v] = 0


used = [0] * N
cnt = 0
dfs(0, used)
print(cnt)

Measured memory_bytes: 42972
x = input()
split_x = x.split()
split_x_int = [int(i) for i in split_x]

W = split_x_int[0]
H = split_x_int[1]
x = split_x_int[2]
y = split_x_int[3]
r = split_x_int[4]

if (x-r) < 0:
	print("No")
elif (x+r) > W:
	print("No")
elif (y-r) < 0:
	print("No")
elif (y+r) > H:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 7740
#include "bits/stdc++.h"

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

int n,k,ar[100000];
ll result,buf;

int main(){
	ios::sync_with_stdio(false);cin.tie();
	while(true){
		result=0;
		cin>>n>>k;

		if(n==0&&k==0) break;

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

		for(int i=0;i<k;i++){
			result+=ar[i];
		}
		buf=result;
		for(int i=k;i<n;i++){
			buf+=ar[i];
			buf-=ar[i-k];
			result=max(result,buf);
		}
		cout<<result<<en;
	}
	return 0;
}

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

template <class T> struct ford_fulkerson {
  struct edge {
    int to, rev;
    T cap;
  };
  static constexpr T inf = numeric_limits<T>::max();
  vector<vector<edge>> g;
  vector<int> vis;
  int time;
  ford_fulkerson(int n) : g(n), vis(n), time(0) {}
  void add_edge(int from, int to, T cap) {
    assert(from != to);
    assert(cap >= 0);
    if (cap == 0) return;
    g[from].push_back({to, (int)g[to].size(), cap});
    g[to].push_back({from, (int)g[from].size() - 1, 0});
  }
  T dfs(int v, int t, T f) {
    if (v == t) return f;
    vis[v] = time;
    for (auto&& e : g[v]) {
      if (vis[e.to] == time or e.cap == 0) continue;
      T d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
    }
    return 0;
  }
  T max_flow(int s, int t) {
    assert(s != t);
    T res = 0;
    while (true) {
      ++time;
      T f = dfs(s, t, inf);
      if (f == 0) return res;
      res += f;
    }
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (auto&& v : a) {
    for (auto&& e : v) {
      cin >> e;
      --e;
    }
  }
  for (int c = 0; c < m; ++c) {
    int s = 2 * n, t = s + 1;
    ford_fulkerson<int> ff(t + 1);
    for (int i = 0; i < n; ++i) {
      ff.add_edge(s, i, 1);
      ff.add_edge(n + i, t, 1);
    }
    for (int i = 0; i < n; ++i) {
      vector<bool> be(n);
      for (int j = c; j < m; ++j) {
        be[a[i][j] / m] = true;
      }
      for (int x = 0; x < n; ++x) {
        if (be[x]) {
          ff.add_edge(i, n + x, 1);
        }
      }
    }
    int f = ff.max_flow(s, t);
    assert(f == n);
    for (int i = 0; i < n; ++i) {
      for (auto e : ff.g[i]) {
        if (e.cap == 0) {
          int j = find_if(begin(a[i]) + c, end(a[i]), [&](int x) {
            return x / m == e.to - n;
          }) - begin(a[i]);
          swap(a[i][c], a[i][j]);
          break;
        }
      }
    }
  }
  for (auto e : a) {
    for (int j = 0; j < m; ++j) {
      cout << e[j] + 1 << " \n"[j == m - 1];
    }
  }
  for (int j = 0; j < m; ++j) {
    vector<int> v;
    for (int i = 0; i < n; ++i) {
      v.push_back(a[i][j]);
    }
    sort(begin(v), end(v));
    for (int i = 0; i < n; ++i) {
      a[i][j] = v[i];
    }
  }
  for (auto e : a) {
    for (int j = 0; j < m; ++j) {
      cout << e[j] + 1 << " \n"[j == m - 1];
    }
  }
}


Measured memory_bytes: 700
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dp[200001][3];
int visit[200001][3];
int arr[200001];
int main(){
	int N;scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d",arr+i);
	for(int i=1;i<=3;i++){
		dp[i][i-1] = arr[i];
		visit[i][i-1] = 1;
	}
	for(int i=1;i<=N;i++){
		for(int j=0;j<2+(N%2);j++){
			for(int k=0;k<2+(N%2);k++){
				int x = i-2-k;
				int y = j-k;
				if(x>0&&y>=0){
					if(visit[i][j]==0){
						visit[i][j]=1;
						dp[i][j] = dp[x][y] + arr[i];
					}
					else dp[i][j] = max(dp[i][j],dp[x][y]+arr[i]);
				}
			}
		}
	}
	ll ret = dp[N-1-(N%2)][0];
	for(int i=1;i<2+(N%2);i++) ret = max(ret,dp[N-1-(N%2)+i][i]);
	printf("%lld",ret);
	
}

Measured memory_bytes: 9536
#include<stdio.h>
int main(){
  char s[13],t;
  scanf("%s",s);
  for(int i=0;i<13;i++){
    if(i<4) t=s[i];
    else if(i==4) t=' ';
    else t=s[i-1];
    printf("%c",t);
  }
  printf("\n");
}

Measured memory_bytes: 128
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $n = $sc->nextInt();

  $t = array();
  $x = array();
  $y = array();
  for ($i = 0; $i < $n; $i++) {
    $t[] = $sc->nextInt();
    $x[] = $sc->nextInt();
    $y[] = $sc->nextInt();
  }



} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $n = 2;
  $t = array(3,6);
  $x = array(1,1);
  $y = array(2,1);



}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

$ans = 'Yes';
$x0 = 0;
$y0 = 0;
$t0 = 0;
for ($i = 0; $i < $n; $i++) {
  if ($i > 0) {
    $x0 = $x[$i-1];
    $y0 = $y[$i-1];
    $t0 = $t[$i-1];
  }
  $x1 = $x[$i];
  $y1 = $y[$i];
  $t1 = $t[$i];

  $x_dist = abs($x1 - $x0);
  $y_dist = abs($y1 - $y0);
  $t_dist = abs($t1 - $t0);

  $a = $t_dist - ($x_dist + $y_dist);

  if ($a >= 0 && $a % 2 == 0) { continue; }
  else { $ans = 'No'; break; }
}



//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


Measured memory_bytes: 47220
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n)cin >> v[i];

    sort(v.rbegin(), v.rend());
    multiset<ll> s;
    for (ll l : v) s.insert(l);
    int ans = 0;
    for (ll a : v) {

        if (s.find(a) == s.end()) continue;
        s.erase(s.find(a));

        ll pair = -1;
        for (ll t = 1; t <= (2 * a); t <<= 1) {
            ll b = t - a;
            if (s.find(b) != s.end()) {
                pair = b;
            }
        }

        if (pair > -1) {
            ans++;
            s.erase(s.find(pair));
        }

    }
    cout << ans << endl;
}


Measured memory_bytes: 14012