akhauriyash/Code-Regression huggingface dataset:
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int MAX_V=10001;
const int inf=INT_MAX;
struct edge{int to,cost,weight;};

class dijk{
    public:
    vector<edge> es[MAX_V];

    int d[MAX_V];
    vector<P> used;
    int V;
    int dijkstra(int s){
        priority_queue<P,vector<P>,greater<P> > que,que2;
        //priority_queue<pp,vector<pp>,greater<pp> > que;
        
        fill(d,d+V,inf);
        d[s]=0;
        que.push(P(0,s));
    
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int dist=p.first;
            int v=p.second;

            if(d[v]<dist) continue;
            
        
            for(int i=0;i<es[v].size();i++){
                edge e=es[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));

                }
            }

        }

        int ans=0;
        //cout<<d[0]<<d[1]<<d[2]<<d[3]<<endl;
        
        for(int i=0;i<V;i++)que2.push(P(d[i],i));
        used.push_back(que2.top());
        que2.pop();
        bool f2[MAX_V];
        f2[s]=true;

        while(!que2.empty()){
            P p=que2.top();
            que2.pop();

            int dist=p.first;
            int v=p.second;
            int tmp=inf;

            for(int i=0;i<es[v].size();i++){
                edge e=es[v][i];
                if(f2[e.to]==true and dist==d[e.to]+e.cost){
                    tmp=min(tmp,e.weight);
                }
            }
            /*
                for(int j=0;j<used.size();j++){
                    if(e.to==get<1>(used[j]) and dist==d[get<1>(used[j])]+e.cost){
                        tmp=min(tmp,e.weight);
                    }
                }
                */
                
            
            ans+=tmp;
            //an[used.size()]=tmp;
            used.push_back(p);
            f2[v]=true;

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

        

    }



};
int main(){
    while(1){
        int a,b;
        scanf("%d%d",&a,&b);
        if(a==0 and b==0) break;
        dijk di;
        for(int i=0;i<b;i++){
            int from,to,cost,weight;
            scanf("%d%d%d%d",&from,&to,&cost,&weight);
            //cout<<from<<to<<cost<<weight<<endl;
            from--;
            to--;
            edge e1,e2;
            e1.to=to;
            e1.cost=cost;
            e1.weight=weight;

            e2.to=from;
            e2.cost=cost;
            e2.weight=weight;
            di.es[from].push_back(e1);
            di.es[to].push_back(e2);

        }
        di.V=a;
        printf("%d\n",di.dijkstra(0));
        //cout<<di.d[a-1]<<endl;

    }
    return 0;

}

Measured memory_bytes: 4420
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	
  sc.Scan()
  s := strings.Split(sc.Text(), " ")
  x, _ := strconv.Atoi(s[0])
  y, _ := strconv.Atoi(s[1])
  
  fmt.Println(gcd(x, y))
}

func gcd(x, y int) int {
  if y > x {
    x, y = y, x
  }

  for y != 0 {
    rem := x % y
    x = y
    y = rem
  }
  
  return x
}




Measured memory_bytes: 1092
#include <iostream>
#include <map>

using namespace std;

int main() {
	int n;
	map<int, int> ma;
	int m;

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

	cin >> m;
	for (int i = 0; i < m; i++) {
		int t;
		cin >> t;
		if (--ma[t] < 0) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 9600
import java.io.*;
import java.util.*;

class Main {
	private static long[] dp;
	private static long[] sum;

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[][] a = new long[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				a[i][j] = sc.nextLong();

		dp = new long[(1 << n)];
		sum = new long[(1 << n)];
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) {
				for (int k = j + 1; k < n; k++) {
					if ((((i >> j) & 1) == 1) && (((i >> k) & 1) == 1)) {
						sum[i] += a[j][k];
					}
				}
			}
		}
		Arrays.fill(dp, -1);
		for (int i = 0; i < n; i++) dp[(1 << i)] = 0;
		System.out.println(solve((1 << n) - 1));
	}

	private static long solve(int s) {
		if (dp[s] != -1) return dp[s];
		long a = 0;
		for (int t = s; t > 0; t &= s) {
			a = Math.max(a, sum[t] + solve(s - t));
			t--;
		}
		dp[s] = a;
		return dp[s];
	}
}


Measured memory_bytes: 25036
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int cntA[N] = {}, cntB[N] = {};
int A[N] = {}, B[N] = {}, ans[N] = {};
struct node {
    int val, a = 0, b = 0;
} arr[N];
struct cmp {
    inline bool operator()(const node &x, const node &y) {
        return x.a + x.b < y.a + y.b;
    }
};
priority_queue<node, vector<node>, cmp> pq;
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
        cntA[A[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        cin >> B[i];
        cntB[B[i]]++;
    }
    for (int i = 1; i <= n; i++)
        if (cntB[i]) pq.emplace(node({i, cntA[i], cntB[i]}));
    bool flag = false;
    for (int i = 1; i <= n; i++) {
        node tmp, R = {0, 0, 0};
        int x, a, b;
        flag = false;
        while (!pq.empty()) {
            tmp = pq.top(), pq.pop();
            //cout << tmp.val << " " << tmp.a << " " << tmp.b << '\n';
            if (tmp.val == A[i]) {
                R = tmp;
                continue;
            }
            x = tmp.val, a = tmp.a, b = tmp.b;
            if (cntA[x] != a || cntB[x] != b) {
                pq.emplace(node({x, cntA[x], cntB[x]}));
                continue;
            }
            flag = true;
            ans[i] = x;
            cntB[x]--;
            if (b > 1) pq.emplace(node{x, cntA[x], cntB[x]});
            break;
        }
        if (R.val) pq.emplace(R);
        if (!flag) break;
        cntA[A[i]]--;
    }
    if (flag) {
        cout << "Yes\n";
        for (int i = 1; i <= n; i++)
            cout << ans[i] << " \n"[i == n];
    }
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 11992
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    cur = 0
    for j in range(N):
        if j < i:
            cur += A[j]
        elif j == i:
            cur += A[j] + B[j]
        else:
            cur += B[j]
    ans = max(ans , cur)
print(ans)

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

typedef long long int lli;

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

    int x;
    cin >> x;

    if(x >= 400 && x <= 599)
    {
        cout << 8 << endl;
    }
    else if(x >= 600 && x <= 799)
    {
        cout << 7 << endl;
    }
    else if(x >= 800 && x <= 999)
    {
        cout << 6 << endl;
    }
    else if(x >= 1000 && x<= 1199)
    {
        cout << 5 << endl;
    }
    else if(x >= 1200 && x <= 1399)
    {
        cout << 4 << endl;
    }
    else if(x >= 1400 && x <= 1599)
    {
        cout << 3 << endl;
    }
    else if(x >= 1600 && x <= 1799)
    {
        cout << 2 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define INF (1<<20)

struct ST {
    int x, y, k;
    ST() {}
    ST(int x, int y, int k) : x(x), y(y), k(k) {}
};
bool operator<(const ST& l, const ST& r) {
    if (l.x != r.x) return l.x < r.x;
    if (l.y != r.y) return l.y < r.y;
    return l.k < r.k;
}

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

int n, m, K, a[128][128], of[128][128];
int vis[128][128][1<<5];
char f[128][128];

int solve() {
    int gx = -1, gy = -1;
    rep (i, n) rep (j, m) if (f[i][j] == 'G') gx = i+1, gy = j+1;
    priority_queue<pair<int, ST> > q;
    rep (i, n) rep (j, m) if (f[i][j] == 'S') q.push(mp(0, ST(i+1, j+1, 0)));
    while (!q.empty()) {
        const pair<int, ST> vv = q.top();
        const ST cur = vv.second;
        q.pop();
        if (vis[cur.x][cur.y][cur.k]) continue;
        vis[cur.x][cur.y][cur.k] = 1;
        if (gx == cur.x && gy == cur.y && (1<<K)-1 == cur.k) return -vv.first;
        rep (d, 4) {
            const int x = cur.x+dx[d], y = cur.y+dy[d];
            if (a[x][y] == INF) continue;
            q.push(mp(vv.first-a[cur.x][cur.y], ST(x, y, cur.k|of[x][y])));
        }
    }
    return 0;
}

int main() {
    scanf("%d%d", &m, &n);
    rep (i, n) rep (j, m) scanf(" %c", f[i]+j);
    rep (i, 128) rep (j, 128) a[i][j] = INF;
    rep (i, n) rep (j, m) if (f[i][j] != '#') a[i+1][j+1] = 1;
    rep (i, n) rep (j, m) if (f[i][j] == '#') {
        for (int x = i-2; x <= i+2; x++) {
            for (int y = j-2; y <= j+2; y++) {
                a[x+1][y+1] = max(a[x+1][y+1], 4-max(abs(x-i), abs(y-j)));
            }
        }
    }
    rep (i, n) rep (j, m) if (f[i][j] == 'M') {
        of[i+1][j+1] = 1<<K;
        K++;
    }
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int i = 0;
		int j = 0;
		int k = 0;
		int ans = 0;
		int answer = 0;

		int[] ary = new int[n];
		for (i = 0; i < n; i++) {
			ary[i] = s.nextInt();

			ans = ans + ary[i];

		}

		int m = s.nextInt();

		int l = 0;
		for (j = 0; j < m; j++) {
			int p = s.nextInt();
			int x = s.nextInt();
			for (l = 0; l < n; l++) {
				if (p-1 == l) {
					if (x < ary[l]) {

						answer = ans - (ary[l]-x);
						System.out.println(answer);
					} else if (x >= ary[l]) {
						answer = ans + (x - ary[l]);
						System.out.println(answer);
					}

				} else {

				}
			}

		}

	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define FOR(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
using namespace std;
bool len(int i) {
	int cnt=0;
	while(i) {
		cnt++;
		i/=10;
	}
	if(cnt%2==1)return true;
	return false;
}
int main() {
	int n,ans=0;
	cin>>n;
	FOR(i,1,n+1) if(len(i))ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,0,n){
        cin >> a[i];
        if(a[i] % 2 == 0 && (a[i] % 3 && a[i] % 5)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

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

string s;
int main(){
    cin >> s;
    bool yes = true;
    for (int i = 0; i < s.size()&&yes; i++) {
        if(i%2==0){
            if(!(s[i]=='R' || s[i]=='U' || s[i]=='D')) yes = false;
        } else{
            if(!(s[i]=='L'||s[i]=='U'||s[i]=='D')) yes = false;
        }
    }
    cout << (yes ? "Yes":"No") << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int n, A[50];

int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1, m) || solve(i+1, m-A[i]);
    return res;
}

int main() {
    int q, M, i;
    
    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (i=0; i<q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }
    
    return 0;
}


Measured memory_bytes: 2688
'use strict';

const receive = require('fs')
  .readFileSync('/dev/stdin', 'utf8')
  .split(/\s/);

const main = input => {
  const S = input[0].split('');
  const ans = S.filter(i => i === '+').length - S.filter(i => i === '-').length;
  console.log(ans);
};

main(receive);

Measured memory_bytes: 7372
import java.util.*;

public class Main {
	static Scanner sc= new Scanner(System.in);
	public static void main(String[] args) {
		long x=sc.nextLong();
		if(x<1200){
			System.out.println("ABC");
		}
		if(x>=1200){
			System.out.println("ARC");
		}
		
	}

}


Measured memory_bytes: 9808
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;
map<string,int> num;
int n;
string now;
int main(){
  // freopen("input.txt","r",stdin);
  cin>>n;
  for(int i = 1;i <= n;i++){
    cin>>now;
    num[now]++;
  }
  printf("AC x %d\n",num["AC"]);
  printf("WA x %d\n",num["WA"]);
  printf("TLE x %d\n",num["TLE"]);
  printf("RE x %d\n",num["RE"]);  
  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  vector<vector<P>> man(n, vector<P>());
  rep(i,n) {
    cin >> a[i];
    rep(j, a[i]) {
      int x, y; cin >> x >> y;
      man[i].push_back(make_pair(x-1, y));
    }
  }

  int maxt = 0;
  for (int b = 1; b<(1<<n); b++) {
    bool flag = true;
    int cnt = 0;
    rep(i,n){
      if (!(1 & (b>>i))) continue;
      else cnt++;
      rep(j,a[i]) {
        int x = man[i][j].first;
        int y = man[i][j].second;
        if ((1 & (b>>x)) != y) { flag = false; break; }
      }
      if (!flag) break;
    }
    if (flag) maxt = max(cnt, maxt);
  }
  cout << maxt << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

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

    int N, W;
    cin >> N >> W;

    const int MAX_V = 1001 * N;
    vector<vector<ll>> dp(2, vector<ll>(MAX_V, -1));
    auto &cur = dp[0], &nxt = dp[1];
    cur[0] = 0;
    for (int i = 0, sum_v = 0; i < N; ++i) {
        int w, v;
        cin >> w >> v;
        for (int j = 0; j <= sum_v; ++j) {
            if (cur[j] == -1) continue;
            nxt[j] = (nxt[j] == -1 ? cur[j] : min(nxt[j], cur[j]));
            nxt[j + v] = (nxt[j + v] == -1 ? cur[j] + w
                          : min(nxt[j + v], cur[j] + w));
        }

        sum_v += v;
        swap(cur, nxt);
    }

    ll max_v = 0;
    for (int v = 0; v < MAX_V; ++v)
        if (cur[v] != -1 && cur[v] <= W) max_v = v;

    cout << max_v << endl;

    return 0;
}


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

int main() {
  int A;
  cin >> A;
  int C;

  vector<int> B(A);
  for(int i = 0; i < A; i++){
    cin >> C;
    B.at(i) = C;
  }

  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());

  int D = 0;
  int F = 0;

  for(int i = 0; i < A; i += 2){
    D += B.at(i);
    if(i + 1 < A){
      F += B.at(i + 1);
    }
  }

  cout << D - F << endl;
}



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

using namespace std;

#define sp << " " <<

struct point
{
    int x;
    int y;
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    double d[n];
    for(int i=0;i<n;i++)
        cin >> d[i];
    double dp[n+1][n+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(i==0)
                dp[i][j]=1;
            else if(j==0)
                dp[i][j]=dp[i-1][j]*(1-d[i-1]);
            else if(j==i)
                dp[i][j]=dp[i-1][j-1]*d[i-1];
            else
                dp[i][j]=dp[i-1][j]*(1-d[i-1])+dp[i-1][j-1]*d[i-1];
        }
    }
    double p;
    for(int i=n/2+1;i<=n;i++)
    {
        p+=dp[n][i];
    }
    cout << fixed << setprecision(10) << p;
    return 0;
}


Measured memory_bytes: 70272
#include<bits/stdc++.h>
using namespace std;
#define N 100000+5
typedef long long ll;
const ll mod=1e9+7;
int n,m;
int a[N];
int b[N];
vector<int>p[N];
int main()
{
	scanf("%d",&n);
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		p[a[i]].push_back(b[i]);
	}
	for(int i=1;i<=n;i++)
	  sort(p[i].begin(),p[i].end());
	for(int i=0;i<m;i++)
	{
 
		int pos=lower_bound(p[a[i]].begin(),p[a[i]].end(),b[i])-p[a[i]].begin()+1;
		printf("%06d%06d\n",a[i],pos);
	}

    return 0;}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main() {
  ll n;
  cin >> n;
  ll ans;
  if(n <= 2){
    ans = 2;
  }else{
    for(ll i = n;;i++){
      bool can = true;
      REP(j,2,sqrt(n)+1){
        if(i % j == 0){
          can = false;
          break;
        }
      }
      if(can){
        ans = i;
        break;
      }
    }
  }
  cout << ans << endl;
}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int main() {
   ll i,j,k;
    ll n;
    cin >>n ;
    for(double i=0; i<50000; i++)
    {
      if(ll(i*1.08)==n)
      {
         cout << i << endl;
         break;
      }
      if(i>=49990)
      {
        cout<< ":("<<endl;
        break;
      }
    }
 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll n,k;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll A[400001];
void init(){
    A[0]=1;
    rep(i,400000) A[i+1]=A[i]*(i+1)%mod;
}
ll nCk(ll n,ll k){
    return A[n]*inv(A[k])%mod*inv(A[n-k])%mod;
}
int main(){
    init();
    cin>>n>>k;
    if(k>=n) k=n-1;
    ll ans=0;
    rep(i,k+1) ans=(ans+nCk(n-1,i)*nCk(n,i)%mod)%mod;
    cout<<ans;
}

Measured memory_bytes: 3328
/* ??????????????´ */

#include <cstdio>
#include <cassert>
using namespace std;

int field[8][8];

int adx[] = {0, 0, 1, 1};
int ady[] = {0, 1, 0, 1};

int bdx[] = {0, 0, 0, 0};
int bdy[] = {0, 1, 2, 3};

int cdx[] = {0, 1, 2, 3};
int cdy[] = {0, 0, 0, 0};

int ddx[] = {0, 1, 1, 0};
int ddy[] = {0, 0, -1, 1};

int edx[] = {0, 1, 1, 2};
int edy[] = {0, 0, 1, 1};

int fdx[] = {0, 0, 1, 1};
int fdy[] = {0, 1, 1, 2};

int gdx[] = {0, 1, 0, -1};
int gdy[] = {0, 0, 1, 1};


bool WithinRange(int y, int x) {
  if (x < 0) return false;
  if (x >= 8) return false;
  if (y < 0) return false;
  if (y >= 8) return false;

  return true;
}

bool Match(int *dx, int *dy) {
  for (int i=-2; i<10; i++) {
    for (int j=-2; j<10; j++) {
      int sum = 0;

      for (int k=0; k<4; k++) {
        int newy = i+dy[k];
        int newx = j+dx[k];
        if (WithinRange(newy, newx)) sum += field[newy][newx];
      }

      if (sum == 4) return true;
    }
  }

  return false;
}

int main() {
  while (1) {
    for (int i=0; i<8; i++) {
      for (int j=0; j<8; j++) {
        char c;
        if (scanf(" %c", &c) != 1) return 0;
        field[i][j] = (c == '1');
      }
    }

    if (Match(adx, ady)) puts("A");
    else if (Match(bdx, bdy)) puts("B");
    else if (Match(cdx, cdy)) puts("C");
    else if (Match(ddx, ddy)) puts("D");
    else if (Match(edx, edy)) puts("E");
    else if (Match(fdx, fdy)) puts("F");
    else if (Match(gdx, gdy)) puts("G");
    else assert(0);
  }
}

Measured memory_bytes: 2564
//ABC109B.cpp
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N,check=0;
	cin>>N;
	string W[N];
	for(int i=0;i<N;i++)cin>>W[i];
	for(int i=1;i<N;i++){
			for(int j=0;j<i;j++){
				if(W[j]==W[i]){
					check=1;
					break;
				}
			}
			if(check==1)break;
			if(W[i-1].back()!=W[i].front()){
				check=1;
				break;
			}
	}
	if(check==1)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

	return 0;
}

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

using namespace std;

const int MAXN = 300010;
int cnt[MAXN];
int f[MAXN];
int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        cnt[a]++;
    }

    vector<int> v;
    for(int i=0;i<MAXN;i++){
        if(cnt[i] > 0){
            v.push_back(cnt[i]);
        }
    }

    sort(v.begin(), v.end());

    int p = 0;
    for(int i=1;i<=n;i++){
        while(p<v.size() && v[p]<i){
            p++;
        }

        f[i] = f[i-1] + v.size() - p;
    }

    for(int i=1;i<=n;i++){
        f[i] /= i;
    }

    p = n;
    for(int i=1;i<=n;i++){
        while(p>0 && f[p] < i)
            p--;
        cout << p<<"\n";
    }

}



Measured memory_bytes: 4336
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C,x,y = Is()
ans = 10**10
for i in range(0,max(x*2,y*2)+3,2):
    a = max(0,(x - i//2)*A)
    b = max(0,(y - i//2)*B)
    c = i*C
    ans = min(a+b+c,ans)
print(ans)

Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int i, N, H[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(H[i]));
	
	int flag = 1;
	for (i = 1, H[0] = 0; i <= N; i++) {
		if (H[i] > H[i-1]) H[i]--;
		else if (H[i] < H[i-1]) flag = 0;
	}
	
	if (flag == 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
 
using namespace std;
 
int main() {
  int n; cin >> n;
  string cs; cin >> cs;
  int sum = 0;
  int i = 0, j = n-1;
  while (i < j) {
    if (cs[i] == 'W' && cs[j] == 'R') {
      cs[i] = 'R'; cs[j] = 'W';
      sum++;
    }
    else if (cs[i] == 'R' && cs[j] == 'R') {
      i++;
    }
    else if (cs[i] == 'W' && cs[j] == 'W') {
      j--;
    }
    else {
      i++; j--;
    }
  }
  cout << sum << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i, m){
        cin >> s[i] >> c[i];
    }

    bool ok = true;
    rep(i, 1000){
        string tmp = to_string(i);
        if(tmp.size() != n) continue;
        //cout << tmp << endl;
        ok = true;
        rep(j, m){
            if(tmp[s[j]-1] != c[j]){
                ok = false;
            }
        }
        if(ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
N,M,X=map(int,input().split())

C=[]
A=[]
for i in range(N):
    t=list(map(int,input().split()))
    C.append(t[0])
    A.append(t[1:])

ans=-1
for i in range(1<<N):     #range(0,2^N)　左ビットシフト
    A_sum=[0]*M             #t=[0 0 0]など len(t)=M
    C_sum=0
    for j in range(N):
        if (i>>j)&1==0:   #jのフラグがないとき
            continue
        C_sum+=C[j]               #合計の値段
        for k in range(M):
            A_sum[k]+=A[j][k]     #合計の理解度  
    if all(x>=X for x in A_sum):  #tのすべての要素がXより大きいとき
        if ans==-1:
            ans=C_sum
        else:
            ans=min(ans,C_sum)
print(ans)

Measured memory_bytes: 9216
n = int(input())
ls = list(map(int, input().split()))
counts = []
for x in ls:
    y = x
    count = 0
    while True:
        if y % 2 == 0:
            y //= 2
            count += 1
        else:
            counts.append(count)
            break
print(sum(counts))

Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
typedef	    long long       ll;
typedef	    vector<ll>      vll;
#define     pb              push_back
#define	    PB              pop_back
#define	    nn              "\n"
#define	    all(p)          p.begin(),p.end()
#define	    zz(v)           (ll)v.size()
#define	    mms(ar,a)       memset(ar,a,sizeof(ar))
#define	    ss              ' '
#define     S(a)            scanf("%lld",&a)
#define     SS(a,b)         scanf("%lld %lld",&a,&b)
#define     SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define     yes             printf("YES\n")
#define     no              printf("NO\n")
#define     P(a)            printf("%lld\n",a)
#define     PP(a,b)         printf("%lld %lld\n",a,b)
#define	    gcd(a,b)        __gcd(a,b)
#define	    lcm(a,b)        (a*b)/gcd(a,b)
#define	    pi              acos(-1.0)
#define	    OO              1000000007

ll  ar[100010],ct[100010];
void solve(){
    ll a,b,i,q,j,t,k,lie,m,n,o,x,y,z;
    ll p=0,sm=0,cnt=0;
    S(n);
    for(i=0;i<n;i++){
        S(ar[i]);
        sm+=ar[i];
        ct[ar[i]]++;
    }
    S(q);
    while(q--){
        SS(a,b);
        if(ct[a]){
            sm-=(a*ct[a]);
            sm-=(b*ct[b]);
            ct[b]+=ct[a];
            ct[a]=0;
            sm+=((b)*ct[b]);
        }
        P(sm);
    }

}

int main(){
//	freopen("input.txt", "r", stdin);
    ll i,t;
//    S(t);
//    while(t--){
        solve();
//    }

    return 0;
}



Measured memory_bytes: 5316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

int n;
cin >> n;

vi A(n);
rep(i,n) cin >> A[i];

rep(i,n){
    if(A[i]%2 == 0){
        if(A[i]%3 != 0 && A[i]%5 != 0){
            cout << "DENIED" << endl;
            return 0;
        }
    }
}

cout << "APPROVED" << endl;


return 0;
}

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

int main() {
	string S;
	cin >> S;
	int max = 0, size = S.size(),cnt=0;
	for (int i = 0; i < size; i++) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'T' || S[i] == 'G') {
			cnt++;
		}
		else {
			if (cnt > max) {
				max = cnt;
			}
			cnt = 0;
		}
	}
		if (cnt > max) {
			max = cnt;
		}
		cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, a, b := nextInt(), nextInt(), []int{}, []int{}
	for i := 0; i < M; i++ {
		a = append(a, nextInt())
		b = append(b, nextInt())
	}

	fmt.Printf("%d\n", ABC054C(N, a, b))
}

// ABC054C ...
func ABC054C(N int, a, b []int) (res int) {
	graph := []GraphNode{}
	for i := 0; i < N; i++ {
		graph = append(graph, GraphNode{i, []int{}})
	}
	for i := 0; i < len(a); i++ {
		graph[a[i]-1].edges = append(graph[a[i]-1].edges, b[i]-1)
		graph[b[i]-1].edges = append(graph[b[i]-1].edges, a[i]-1)
	}

	return dfsABC054(graph[0], graph, []int{}, 0)
}

func dfsABC054(current GraphNode, graph []GraphNode, path []int, res int) int {
	for _, n := range path {
		if n == current.id {
			return res
		}
	}

	path = append(path, current.id)
	if len(path) == len(graph) {
		return res + 1
	}

	for _, e := range current.edges {
		res = dfsABC054(graph[e], graph, path, res)
	}

	return res
}

// GraphNode ...
type GraphNode struct {
	id    int
	edges []int
}


Measured memory_bytes: 1828
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


const int MOD = 100000;

int W, H;
int dp[105][105][3][3];

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

int solve(int x, int y, int to, int ren) { //to 0:east 1:north
	if (x == W - 1 && y == H - 1) return 1;
	if (dp[x][y][to][ren] != -1) return dp[x][y][to][ren];

	int ret = 0;
	ret += solve(x + dx[to], y + dy[to], to, 0);
	if (ren != 1) {
		ret += solve(x + dy[to], y + dx[to], (to+1)%2, 1);
	}

	return dp[x][y][to][ren] = ret%MOD;
}

int main() {
	while (cin >> W >> H, W)
	{
		rep(i, W)rep(j, H)rep(k, 2)rep(l, 3) {
			dp[i][j][k][l] = -1;
		}
		cout << (solve(0, 0, 0, 1) + solve(0, 0, 1, 1))%MOD << endl;
	}

	return 0;
}



Measured memory_bytes: 3456
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<complex>

using namespace std;

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

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb(i) push_back(i)
#define fs first
#define sc second

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

int main(){
	int a,b,c;
	while(cin >> a >> b >> c){
		int cnt = 0,t = a+b;

		reps(i,1,10){
			if(i!=a && i!=b && i!=c)cnt += t+i>20;
		}
		cout << (cnt>3?"NO":"YES") << endl;

	}
	
	return 0;
}

Measured memory_bytes: 1152
#if defined(LOCAL)
#define PROBLEM_NAME "b"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) debug(x)
#else
#define L(x...) (x)
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

void solve(istream& cin, ostream& cout) {
  l n; cin >> n;
  vl v(n);
  F(i, 0, n) {
    l x; cin >> x; x--;
    if (x == i) v[i] = 1;
  }
  l answer = 0;
  F(i, 0, n) {
    if (v[i] == 0) continue;
    v[i] = 0;
    if (i + 1 < n) v[i + 1] = 0;
    answer++;
  }
  cout << answer << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
void solve(long long x);
int main()
{
	long long n;
	cin>>n;
	solve(n);
	return 0;
}
void solve(long long x)
{
	if (x!=0)
	{
		int d=x%26;
		if (d==0)   solve(x/26-1);
		else   solve(x/26);
		if (d==0)   putchar('z');
		else   putchar('a'+d-1);
	}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n, h, w, a[500000], col[200][200];
int main(){
    cin >> h >> w;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    int c = 1;
    for(int i = 1; i <= h; ++i){
        if(i & 1)
            for(int j = 1; j <= w; ++j){
                if(a[c] == 0)++c;
                col[i][j] = c;
                a[c]--;
            }
        else
            for(int j = w; j; --j){
                if(a[c] == 0)++c;
                col[i][j] = c;
                a[c]--;
            }
        for(int j = 1; j <= w; ++j)
            printf(j ? " %d":"%d", col[i][j]);
        printf("\n");
    }
    return 0;
}

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

typedef map<int,int>mpii;

#define fast ios_base::sync_with_stdio(0)

int main()
{
    fast;
    mpii mp;
    int i , N , cnt=0;
    cin >> N;
    for(i=0; i<N; i++)
    {
        int x;
        cin >> x;
        mp[x]++;
        if(mp[x] == 1) cnt++;
        else mp[x] = 0, cnt--;
    }

    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 4992
import java.util.*; 
 
public class Main
{
	public static void main(String args[]) throws Exception{
		new Main().run();
	}
	
	public void run()
	{
		int i,j,k;
		Scanner cin=new Scanner(System.in);
		while(true){
			String s = cin.nextLine();
			if(s.equals(".")) break;
			int count = 0;
			for(i=0;i<3;i++){
				for(j=0;j<3;j++){
					for(k=0;k<3;k++){
						String ss = s;
						ss = ss.replace("P", i + "");
						ss = ss.replace("Q", j + "");
						ss = ss.replace("R", k + "");
						while(true){
							ss = ss.replace("-0", "2");
							ss = ss.replace("-1", "1");
							ss = ss.replace("-2", "0");
							ss = ss.replace("(0+0)", "0");
							ss = ss.replace("(0+1)", "1");
							ss = ss.replace("(0+2)", "2");
							ss = ss.replace("(1+0)", "1");
							ss = ss.replace("(1+1)", "1");
							ss = ss.replace("(1+2)", "2");
							ss = ss.replace("(2+0)", "2");
							ss = ss.replace("(2+1)", "2");
							ss = ss.replace("(2+2)", "2");
							
							ss = ss.replace("(0*0)", "0");
							ss = ss.replace("(0*1)", "0");
							ss = ss.replace("(0*2)", "0");
							ss = ss.replace("(1*0)", "0");
							ss = ss.replace("(1*1)", "1");
							ss = ss.replace("(1*2)", "1");
							ss = ss.replace("(2*0)", "0");
							ss = ss.replace("(2*1)", "1");
							ss = ss.replace("(2*2)", "2");
							if(ss.length()==1) break;
						}
						if(ss.equals("2")){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
	
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int a[2][230];
//int t[100005] , x[100005] , y[100005];
int main(){
	dhoom;
	int n;
	cin >> n;
	for(int i = 0 ; i <= 1 ; i++){
		for(int j = 1 ; j <= n ; j++)
			cin >> a[i][j];
	}
	for(int i = 1 ; i <= n ;i++)
		a[0][i] += a[0][i-1];
	for(int j = 1 ; j <= n ; j++){
		a[1][j] = a[1][j] + max(a[1][j-1] , a[0][j]);
	}
	cout << a[1][n] << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()
C = [0] + LIST()

ans = 0
for i in range(1, N):
    if A[i-1]+1 == A[i]:
        ans += C[A[i]-1]
ans += sum(B)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	ll N, ans = 0; cin >> N;
	ll A[N+1], L[N+1], R[N+1];
	rep(i, N+1){ cin >> A[i]; ans+=A[i]; }
	if(N==0){
		if(A[0] == 1) cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	L[0] = R[0] = 1;
	if(A[0] != 0){
		cout << -1 << endl;
		return 0;
	}
	rep(i, N){
		L[i+1] = L[i] - A[i+1], R[i+1] = 2*R[i] - A[i+1];
		if(R[i+1] > inf) R[i+1] = inf;
		if(R[i+1]<0){
			cout << -1 << endl;
			return 0;
		}
		if(L[i+1]<0) L[i+1] = 0;
	}
	if(L[N]!=0){
		cout << -1 << endl;
		return 0;
	}
	ll pre = 0;
	for(int i=N-1; i>=0; i--){
		if(pre+A[i+1] < R[i]){ ans += pre+A[i+1]; pre+=A[i+1]; }
		else{ ans += R[i]; pre = R[i]; }
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b;
string s[100];

int main() {
	cin >> a >> b;
	a--; b--;
	
	inc(i, 100) {
		s[i] = string(100, (i < 50 ? '#' : '.'));
	}
	
	inc(k, a) {
		int i = k / 23;
		int j = k % 23;
		s[1 + i * 2][1 + j * 2] = '.';
	}
	inc(k, b) {
		int i = k / 23;
		int j = k % 23;
		s[50 + 1 + i * 2][1 + j * 2] = '#';
	}
	
	cout << "100 100\n";
	inc(i, 100) { cout << s[i] << "\n"; }
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int cnt = 0;
  for (int i = 1; i+1 < n; i++) {
    if ((v.at(i-1) < v.at(i) && v.at(i) < v.at(i+1)) ||
        (v.at(i+1) < v.at(i) && v.at(i) < v.at(i-1))) {
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
const int MAX_N = 100;
const int INF = 999999999;
using namespace std;

int n;
int color[MAX_N];
bool adj[MAX_N][MAX_N];
int d[MAX_N];

void bfs(int s) {
    queue<int> que; que.push(s);
    for (int i = 0; i < n; i++) d[i] = INF;
    d[s] = 0;

    int u;
    while (!que.empty()) {
        u = que.front(); que.pop();
        for (int v = 0; v < n; v++) {
            if (adj[u][v] && d[v] == INF) {
                d[v] = d[u] + 1;
                que.push(v);
            }
        }
    }
}
int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            adj[i][j] = false;
        }
    }

    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            adj[u-1][v-1] = true;
        }
    }

    bfs(0);

    for (int i = 0; i < n; i++) {
        if (d[i] != INF) {
            cout << i+1 << " " << d[i] << endl;
        } else {
            cout << i+1 << " " << -1 << endl;
        }
    }

    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int n = 0, k = S.size(), m, Max = 0;
    int len[10];
    for(int i = 0; i < k; i++) len[i] = 0;
    for(int i = 0; i < k; i++){
        m = i;
        while(S[i] == 'A' || S[i] == 'C'|| S[i] == 'G'|| S[i] == 'T'){
            len[m]++;
            i++;
        }
    }
    for(int i = 0; i < k;i++){
        if(Max < len[i]) Max = len[i];
    }
    cout  << Max << endl;
    return 0;
}


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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif



int main(int argc, char **argv){
	int weight[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
	int w = 0;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	while(ifs >> w){
#else
	while(std::cin >> w){
#endif
		std::vector<int> binary_expression;
		std::vector<int> result;
		while(w > 0){
			binary_expression.push_back(w % 2);
			w = w / 2;
		}

		for(int i = 0; i < binary_expression.size(); i++){
			if(binary_expression[i] > 0){
				result.push_back(weight[i]);
			}
		}
		
		std::cout << result[0];
		for(int i = 1; i < result.size(); i++){
			std::cout << " " << result[i];
		}
		std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3148
# coding: utf-8
# Your code here!

N=int(input())
a4=[[0,0,0]]
for i in range(N):
    t,x,y=[int(i) for i in input().split()]
    #例えば[-y,x]とかにして正負とか左右とか入れ替えも可能です
    a4.append([t,x,y])
flag = 0

#print(a4)


for i in range(N):
    dist = abs(a4[i+1][1] - a4[i][1]) + abs(a4[i+1][2] - a4[i][2])
    tdist = a4[i+1][0] - a4[i][0]
 #   print(dist)
    if dist > tdist or  (dist - tdist)%2 == 1:
        flag = -1
#        print('FNO')

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




Measured memory_bytes: 19572
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 100005
int N;
ll K;
vector<int> G[MXN];
ll ans;

void dfs(int u, int p=-1, int d=0)
{
    int dep = min(2,d+1);
    ll mul = K-dep; 
    ll C = SZ(G[u]);
    if(p!=-1)C--;
    if( mul < C )
    {
        ans=0;
        return;
    }
    for( int v : G[u] )
    {
        if( v==p )continue;
        ans=(ans*(mul--))%MOD;
        dfs(v,u,d+1);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N>>K;
    int u,v;
    FOR(i,1,N-1)
    {
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
    ans=K;
    dfs(1);
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 11648
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int inf = 1e9;

template <class T>
istream& operator>>(istream& ss, vector<T>& v) {
	for (int i = 0; i < v.size(); i++) ss >> v[i];
	return ss;
}

template <class T> 
ostream& operator<<(ostream& ss, const vector<T>& v) {
	for (int i = 0; i < v.size(); i++) ss << v[i] << ' ';
	return ss;
}

void solve(){
	int k, a, b;
	cin >> k >> a >> b;
	if (b / k - (a - 1) / k > 0) cout << "OK";
	else cout << "NG";
}

int main(){
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++){
		solve();
	}
}

Measured memory_bytes: 3596
import java.util.Collections;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextInt()) {
				int num = sc.nextInt();
				map.put(num, map.containsKey(num) ? map.get(num) + 1 : 1);
			}

			int maxValue = Collections.max(map.values());
			for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
				if (maxValue == entry.getValue()) {
					System.out.println(entry.getKey());
				}
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26184