akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>

int main()
{
    int n;
    cin>>n;
    int dist[n+10];
    for(int i=0; i<n+10; i++) dist[i] = 10000000;
    deque<int> dq;
    dq.push_front(1);
    dist[1] = 0;
    while(!dq.empty()){
        int u = dq.front();
        dq.pop_front();
        if(u==0) break;
        int v = (u+1)%n;
        if(dist[v]>dist[u]+1 && u!= v){
            dist[v] = dist[u] + 1;
            dq.push_back(v);
        }
        v = (u*10)%n;
        if(dist[v]>dist[u] && u!= v){
            dist[v] = dist[u];
            dq.push_front(v);
        }
    }
    cout<<dist[0] + 1<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
//#define int long long
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int count = 0;
  int subcount = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % 4 == 0) count++;
    else if (a[i] % 2 == 0) subcount++;
  }
  if(subcount != 0) n -= (subcount-1);
  
  if ((n/2) <= count) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int A, B, C;
        private void Scan()
        {
            var sc = new Scanner();
            A = sc.NextInt();
            B = sc.NextInt();
            C = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            Console.WriteLine((A+B)>=C?"Yes":"No");
        }


        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 11092
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;
#define scii(x, y)     int x, y;    scanf("%d%d", &x, &y);
int main() {
  scii(A,B);
  string ans;
  if(A>B)ans="Alice";
  if(A<B)ans="Bob";
  if(B==1)ans="Bob";
  if(A==1)ans="Alice";
  if(A==B)ans="Draw";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
f=0
t=-1
for i in range(n):
 if t == a[i]-1:
  f+=c[t-1]
 f+=b[a[i]-1]
 t=a[i]
print(f)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main () {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int monter1 = (A+D-1) / D;
  int monter2 = (C+B-1) / B;
  cout << (monter1 >= monter2 ?  "Yes" : "No");
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll, int>
const ll INF = (1ll<<60);
ll d[100100];
vector<P> g[100100];
priority_queue<P, vector<P>, greater<P> > pq;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n,m,l,r;
	ll c;
	cin >> n >> m;
	for(int i = 0 ;i < 100100 ;i++)d[i]=INF;
	d[0] = 0ll;
	pq.push(P(d[0],0));
	for(int i=1; i<n; ++i){
		g[i].push_back(P(0ll,i-1));
	}
	for(int i=0; i<m; ++i)
    {
		cin >> l >> r >> c;
		--l; --r;
		g[l].push_back(P(c,r));
	}
	while(!pq.empty())
    {
		l = pq.top().second;
		c = pq.top().first;
		pq.pop();
		if(c>d[l])
			continue;
		for(int i=(g[l].size()-1); i>=0; --i)
		{
			r = g[l][i].second;
			c = g[l][i].first;
			if(d[r] > d[l] + c)
            {
				d[r] = d[l] + c;
				pq.push(P(d[r],r));
			}
		}
	}
	if(d[n-1]<INF)cout<<d[n-1];
	else cout<<-1;
	return 0;
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1000000007;
using us = unsigned short;

int mod(int x){
	return x % MOD;
}

int main(void)
{
    IOS
    //constexpr int A = 50;
    constexpr int N = 50 + 1;
    constexpr int X = 50;
    // dp[枚数][合計]=組み合わせ数
    ll dp[N][N*X];
    REP(i,N) REP(j,N*X) dp[i][j]=0;

    int n,a; cin >> n >> a;
    vector<int> v(n);
    REP(i,n) cin >> v[i];

    REP(i,n) {
        for(int j = i+1; j > 0 ;j--) {
            if (j == 1) {
                dp[j][v[i]]++;
                //cerr << v[i] << endl;
            } else {
                FOR(k,0,X*(i+1)) {
                    dp[j][k+v[i]] += dp[j-1][k];
                }
            }
        }
    }
    
    ll ans = 0;
    FOR(i,1,n+1) ans = ans + dp[i][a*i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<vector>
#include<complex>
#include<algorithm>

#define	mp			make_pair
#define	pb			push_back
#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

typedef	complex<double>	Point;

const double EPS=1e-9;

class Line:public vector<Point>{
public:
	Line(){}
	Line(const Point &a,const Point &b){ pb(a),pb(b); }
};

class Segment:public Line{
public:
	Segment(){}
	Segment(const Point &a,const Point &b):Line(a,b){}
};

double dot(const Point &a,const Point &b){
	return real(a)*real(b)+imag(a)*imag(b);
}

double cross(const Point &a,const Point &b){
	return real(a)*imag(b)-imag(a)*real(b);
}

enum {CCW=1,CW=-1,ON=0};
int ccw(const Point &a,Point b,Point c){
	b-=a,c-=a;
	double rotdir=cross(b,c);
	if(rotdir>EPS)		return CCW;
	if(rotdir<-EPS)		return CW;
	return ON;
}

inline void calc_abc(const Line &l,double &a,double &b,double &c){	// l : ax+by+c=0
	a=imag(l[0])-imag(l[1]);
	b=real(l[1])-real(l[0]);
	c=cross(l[0],l[1]);
}

bool intersect(const Segment &s,const Segment &t,Point *p=NULL){
	if(max(real(s[0]),real(s[1]))<min(real(t[0]),real(t[1]))-EPS
	|| max(real(t[0]),real(t[1]))<min(real(s[0]),real(s[1]))-EPS
	|| max(imag(s[0]),imag(s[1]))<min(imag(t[0]),imag(t[1]))-EPS
	|| max(imag(t[0]),imag(t[1]))<min(imag(s[0]),imag(s[1]))-EPS)	return false;

	if(ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1])<=0
	&& ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1])<=0){
		if(p){
			double a1,b1,c1,a2,b2,c2;
			calc_abc(s,a1,b1,c1);
			calc_abc(t,a2,b2,c2);
			double det=a1*b2-a2*b1;
			if(abs(det)<EPS){	// s is parallel to t
				Point q[3]={s[0],s[1],t[0]};
				rep(i,3){
					if(dot(q[i]-s[0],q[i]-s[1])<EPS && dot(q[i]-t[0],q[i]-t[1])<EPS){
						*p=q[i];
						break;
					}
				}
			}
			else	*p=Point(b1*c2-b2*c1,a2*c1-a1*c2)/det;
		}
		return true;
	}
	return false;
}

int n;
Point A,B;
Segment AB,S[100];
bool own[100],loc[100];

int solve(){
	vector< pair<double,int> > pts;
	rep(i,n){
		Point Q;
		if(intersect(AB,S[i],&Q))	pts.pb(mp(abs(A-Q),i));
	}
	if(pts.size()==0)	return 0;

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

	int cnt=0,id=pts[0].second;
	bool now=(own[id]?loc[id]:!loc[id]);
	for(int i=1;i<pts.size();i++){
		id=pts[i].second;
		if(own[id]){
			if(now!=loc[id]){ cnt++; now=!now; }
		}
		else{
			if(now==loc[id]){ cnt++; now=!now; }
		}
	}
	return cnt;
}

int main(){
	int T;	scanf("%d",&T);
	while(T--){
		int xa,ya,xb,yb;	scanf("%d%d%d%d%d",&xa,&ya,&xb,&yb,&n);
		A=Point(xa,ya);
		B=Point(xb,yb);
		AB=Segment(A,B);
		rep(i,n){
			int x1,y1,x2,y2,o,l;	scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&o,&l);
			S[i]=Segment(Point(x1,y1),Point(x2,y2));
			own[i]=o;
			loc[i]=l;
		}
		printf("%d\n",solve());
	}

	return 0;
}

Measured memory_bytes: 844
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC104C
{
    class Program
    {
        static int D, G;
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            D = input[0];
            G = input[1];
            
            
            string[] line;
            int[] p = new int[D];
            int[] c = new int[D];
            for(int i = 0 ; i < D ; i++)
            {
                line = Console.ReadLine().Split(' ');
                p[i] = int.Parse(line[0]);
                c[i] = int.Parse(line[1]);
            }
            
            int ans = 999999999;
            for(int bit = 0 ; bit < 1 << D ; ++bit)
            {
                int num = 0, total = 0;
                for(int i = 0 ; i < D ; i++)
                {
                    if((bit & 1 << i) != 0)
                    {
                        total += p[i] * 100 * (i+1) + c[i];
                        num += p[i];
                    }
                }
                
                if(total >= G)
                {
                    ans = Math.Min(num, ans);
                    continue;
                }
                
                for(int i = D-1 ; i >= 0 ; i--)
                {
                    if((bit & 1 << i) != 0) continue;
                    for(int j = 0 ; j < p[i]; j++)
                    {
                        total += (i + 1) * 100;
                        num++;
                        if(total >= G) break;
                    }
                    if(total >= G) break;
                }
                ans = Math.Min(num, ans);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl; 
}

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

int main()
{
	int N, i, j, tmp = 0;
	int A[200000];

	cin >> N;

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

	sort(A, A + N);

	for (i = 0; i < N; i++){

			if (A[i] == A[i + 1]) {

				cout << "NO";
				return 0;
			}


	}


	cout << "YES";

}


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

long long int N, a, b[100000], i;
char c;

static inline long long int p(long long int n){
    static long long int ret = 1, bi = 2;
    while(n){
        if(n & 1){
            ret = (ret * bi) % 1000000007;
        }
        bi = (bi * bi) % 1000000007;
        n >>= 1;
    }
    return ret;
}

int main(){
    for(c = getchar();c != 10;c = getchar()){
        N = ((N * 5) << 1) + c - 48;
    }
    ++(*b);
    for(i = 0; i < N; ++i){
        for(c = getchar(), a = 0;c != 32 && c != 10;c = getchar()){
            a = ((a * 5) << 1) + c - 48;
        }
        ++b[a];
    }
    for(i = ~N & 1; i < N; i += 2){
        if(b[i] != 2){
            puts("0");
            return 0;
        }
    }
    cout << p(N >> 1) << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int w = Integer.parseInt(in.next());
            int h = Integer.parseInt(in.next());
            int n = Integer.parseInt(in.next());
            int points[][] = new int[n][3];
            for (int i = 0; i < n; i++) {
                points[i][0] = Integer.parseInt(in.next());
                points[i][1] = Integer.parseInt(in.next());
                points[i][2] = Integer.parseInt(in.next());
            }

            int board[][] = new int[w][h];  // 0 : white 1 : black
            long ans = 0;

            for (int i = 0; i < n; i++) {
                if (points[i][2] == 1) {
                    for (int j = 0; j < points[i][0]; j++) {
                        for (int k = 0; k < h; k++) {
                            board[j][k] = 1;
                        }
                    }
                } else if (points[i][2] == 2) {
                    for (int j = points[i][0]; j < w; j++) {
                        for (int k = 0; k < h; k++) {
                            board[j][k] = 1;
                        }
                    }
                } else if (points[i][2] == 3) {
                    for (int j = 0; j < w; j++) {
                        for (int k = 0; k < points[i][1]; k++) {
                            board[j][k] = 1;
                        }
                    }
                } else if (points[i][2] == 4) {
                    for (int j = 0; j < w; j++) {
                        for (int k = points[i][1]; k < h; k++) {
                            board[j][k] = 1;
                        }
                    }
                }
            }

            for (int i = 0; i < w; i++) {
                for (int j = 0; j < h; j++) {
                    if (board[i][j] == 0) ans++;
                }
            }

            out.println(ans);
        }

    }
}



Measured memory_bytes: 22816
from math import floor,ceil,sqrt
import fractions
import collections
import itertools
import pprint
from collections import deque
N,K=map(int,input().split())
A=list(map(int,input().split()))
double=[[-1 for _ in range(N)] for _ in range(60)]

for i in range(N):
    double[0][i]=A[i]-1
#pprint.pprint(double)
for i in range(1,60):
    for j in range(N):
        bef=double[i-1][j]
        double[i][j]=double[i-1][bef]
        #pprint.pprint(double[:10])
        #input()
bit=[0]*60

for i in range(60):
    if (K>>i)&1:
        bit[i]=1
#print(double[:5],bit)
piv=0
for i in range(60):
    if bit[i]==1:
        piv=double[i][piv]
print(piv+1)





Measured memory_bytes: 220552
//
// Created by HDawn on 2020/6/30.
//
/*
 * #include <stdio.h>

int n, T;

int Binary_Search(int a[],int key) {
    int left = 0;
    int right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (a[mid] == key) {
            return 1;
        } else if (key < a[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}

int main() {
    scanf("%d",&n);
    int a[n+1];
    for (int i = 0; i < n; ++i) {
        scanf("%d",&a[i]);
    }
    scanf("%d",&T);
    int b;
    int ans=0;
    for (int i = 0; i < T; ++i) {
        scanf("%d",&b);
        if (Binary_Search(a,b)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

 */
#include <bits/stdc++.h>

using namespace std;
int n, T;
int ans;

int Binary_Search(int a[],int key) {
    int left = 0;
    int right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (a[mid] == key) {
//            ans++;
            return 1;
        } else if (key < a[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}


int main() {
    cin >> n;
    int a[n+1];
    for (int i = 0; i < n; ++i) {
//        cin >> a[i];
        scanf("%d",&a[i]);
    }
    sort(a, a + n);
    cin >> T;
    int b;
    for (int i = 0; i < T; ++i) {
//        cin >> b;
        scanf("%d",&b);
        if (Binary_Search(a,b)) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3600
while True:
    n = int(input())
    if n == 0: break
    l = [map(int,input().split()) for i in range(n)]
    P, Q, R, C = map(int,input().split())
 
    ans = [i for i,p,q,r in l if p<=P and q<=Q and r<=R and p*4+q*9+r*4<=C]
 
    if len(ans):
        for i in ans:
            print (i)
    else :
        print ("NA")


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

int main(){
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for(int i = 0; i <= K; i++){
    for(int j = 0; j <= K; j++){
      if(0 <= S - i - j && S - i - j <= K){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if (A1 + A2 + A3 >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int root(int arr[],int i){
    while(arr[i]!=i){
         arr[i]=arr[arr[i]];
        i=arr[i];
    }
    return i;
}
void Union(int arr[],int Size[],int a,int b){
int rootA=root(arr,a);
int rootB=root(arr,b);
if(Size[rootA]<Size[rootB]){
    arr[rootA]=arr[rootB];
    Size[rootB]+=Size[rootA];
}else{
arr[rootB]=arr[rootA];
Size[rootA]+=Size[rootB];
}
}
bool findRoot(int a,int b,int arr[]){
 if(root(arr,a)==root(arr,b))return true;
 else return false;
}

bool nCyc=false;
/*void dijkstra(int v,long long dis[]){
dis[v]=0;
multiset<pair<int,int> >s;
s.insert({0,v});
while(!s.empty()){
    pair<int,int>p= *s.begin();
    s.erase(s.begin());
    int x=p.second;
  if(vis[x])continue;
    vis[x]=1;
    for(int i=0;i<adj[x].size();i++){
        int e=adj[x][i].first,w=adj[x][i].second;
      //  cout<<dis[e]<<" "<<dis[x]+w<<endl;
        if(dis[e]>dis[x]+w){
            dis[e]=dis[x]+w;
            s.insert(make_pair(dis[e],e));
        }
    }
}
}*/
/*void bfs(int s){
    queue<int>q;
    q.push(s);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int i=0;i<adj[v].size();i++){
            if(!vis[adj[v][i]]){
                 q.push(adj[v][i]);
                 vis[adj[v][i]]=1;
            }
        }
    }
}*/

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/*bool isVal(int i,int j){
      if(i<0 || j<0 || j>=m || i>=n)return false;
      return true;
}*/
/*void dfs(int i,int j) {

    if(!isVal(i,j) || vis[i][j] || arr[i][j]=='#')return;
      vis[i][j]=1;
	  if(arr[i][j]=='G'){
	  check++;
	  }
	  if(arr[i][j]=='B'){
        b=1;
        return;
	  }
	for(int k=0;k<4;k++){
     int pos1=i+dx[k],pos2=j+dy[k];
   //  cout<<pos1<<" "<<pos2<<endl;
     if( isVal(pos1,pos2) && (arr[pos1][pos2]=='#'))continue;
               dfs(pos1,pos2);
	}
}
void dfs2(int i,int j){
 if(isVal(i,j)==false || arr[i][j]!='.')return;
  arr[i][j]='#';
}*/
/*
double prim(int x){
    priority_queue<pair<double,int>,vector<pair<double,int> >,greater<pair<double,int> > >q;
    double min_cost=0.0;
    pair<double,int>p;
     q.push(make_pair(0.0,x));
     while(!q.empty()){
      p=q.top();
      q.pop();
      x=p.second;
      if(vis[x])continue;
      min_cost+=p.first;
      vis[x]=1;
      for(int i=0;i<adj[x].size();i++){
         int y=adj[x][i].second;
         if(!vis[y]){
            q.push(adj[x][i]);
        }
      }
     }
   return min_cost;
}*/
string s,t;
int dp[1005][1005];
int solve(int i,int j){
return 0;
}
int freq[200005],check[100005];
vector<vector<int> >adj(55);
//int ans[55][55];
int vis[55];
void dfs(int s,int parent){
vis[s]=1;
for(int i=0;i<adj[s].size();i++){
    if(!vis[adj[s][i]]){
//        ans[parent][adj[s][i]]=1;
        dfs(adj[s][i],parent);
    }
}
}
int main()
{
//freopen("diamond.in", "r", stdin);
//freopen("diamond.out","w", stdout);
   int n;
   cin>>n;
   if(n%1000==0)cout<<0;
   else cout<<(1000)-(n%1000);
return 0;
}



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

int main(){
    int n,m;
    cin >> n >> m;
    ll ans = (1900*m +100*(n-m)) * pow(2,m);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
      	string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int x = int.Parse(input[1]);
		int y = int.Parse(input[2]);
        int[] cnt = new int[n-1];
        double midxy = (double)(x+y-1)/2;

        for(int g = 0; g < n-1; g++) cnt[g] = 0;
        for(int i = 0; i < n-1; i++)
        {
          byte code;
          if(i+1 < x) code = 0;
          else if(i+1 <= midxy) code = 1;
          else code = 2;
          for(int j = i+1; j < n; j++)
          {
            int dist = 0;
            switch(code)
            {
              case 0:
                if(j+1 <= midxy + 1) dist = j - i;
                else if(j+1 <= y) dist = x - (i + 1) + 1 + y - (j + 1);
                else dist = x - (i + 1) + 1 + (j + 1) - y;
                break;
                
              case 1:
                if(j+1 <= midxy + 1) dist = j - i;
                else if(j+1 <= y)
                {
                  int d1 = j - i;
                  int d2 = y - x + 1 - d1;
                  dist = d1 < d2 ? d1 : d2;
                }
                else dist = (i+1) - x + 1 + (j+1) - y;
                break;
                
              case 2:
                dist = j - i;
                break;              
            }
            
            //Console.WriteLine(dist);
            cnt[dist-1] = cnt[dist-1] + 1;
          }
        }
      
        foreach(int ans in cnt) Console.WriteLine(ans);

	}
}

Measured memory_bytes: 11204
# coding: utf-8
import sys
from collections import deque

output_str = deque()
data_cnt =  int(input())  

for i in range(data_cnt):
    line = input().rstrip()
    if line.find(" ") > 0:
        in_command, in_str = line.split(" ")
    else:
        in_command = line
    
    if in_command == "insert":
        output_str.appendleft(in_str)
    elif in_command == "delete":
        if output_str.count(in_str) > 0:
            output_str.remove(in_str)
    elif in_command == "deleteFirst":
        output_str.popleft()
    elif in_command == "deleteLast": 
        output_str.pop()

print(" ".join(output_str))

Measured memory_bytes: 71704
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
vector<int> a;
int n;
bool isOK(int m, int key) {
	int sum = 0;
	rep(i, 0, n) {
		sum += (a[i] - 1) / m;
	}
	return sum <= key;
}
int my_binary_search(int key) {
	int left = 0;
	int right = 0;
	rep(i, 0, n)right = max(right, a[i]);

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main(void) {
	int k;
	cin >> n >> k;
	a.resize(n);
	rep(i, 0, n)cin >> a[i];
	printf("%d\n", my_binary_search(k));
	return 0;
}


Measured memory_bytes: 4032
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int K;
    cin >> K;
    cout << (K / 2) * ((K+1) / 2) << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    static void solve(Scanner in) {
        char[] S = in.next().toCharArray();
        int score = 0;
        for (int i = 0; i < S.length; i++) {
            if (i % 2 > 0) { // p
                if (S[i] == g)
                    score++;
            } else { // g
                if (S[i] == p)
                    score--;
            }
        }

        System.out.println(score);
    }

    static final char p = 'p';
    static final char g = 'g';

    // ggppgggpgg

    // count(p) <= count(g)
}

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

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    ll n,k;
    cin >> n >> k;
    if (n < k){
        cout << min(k-n,n) << "\n";
    }else if (n == k){
        cout << 0 << "\n";
    }else{
        cout << min(n%k,-1*(n%k - k)) << "\n";
    }
}

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

const int maxn=2e3+5,pps=1e9+7;

int n,m,k,ans,len;
int f[maxn<<1][maxn];

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

int main() {
	n=read(),m=read(),k=read();
	len=(n+m-1)/(k-1);
	for(int i=1;i<k;i++)
		f[1][i]=1;
	for(int i=2;i<=len;i++)
		for(int j=1;j<=n;j++) {
			f[i][j]=(f[i-1][j]+f[i][j-1])%pps;
			if(j>=k)f[i][j]=(f[i][j]+pps-f[i-1][j-k])%pps;
		}
	for(int i=1;i<=len;i++) {
		int limit=max(0,i*(k-1)-m)+1;
		for(int j=n;j>=limit;j-=k-1)
			ans=(ans+f[i][j])%pps;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string word;
    int cou[256]={0};
    cin>>word;
    for(int i=0;i<word.length();i++)cou[word[i]]++;
    cout<<min(min(cou['K'],cou['U']),min(cou['P'],cou['C']))<<endl;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  int n,sum=0;
  cin>>n;
  vector<int> a(n);
  r(i,n){
    cin>>a.at(i);
    sum+=a.at(i)-1;
  }
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
	long long n,m;
	cin >> n >> m;
	long long ans=0;
	if(n>m/2){
		cout << m/2 << endl;
	}else{
		cout << n+(m-n*2)/4 << endl;
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <math.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const int inf = 2e9;
const ll N = 2e5+1;
const ll mod = 1e9+7;

vector<int>adj[N];
int arr[N];
int ans[N];

void dfs(int node,int par,vector<int>&lis,stack<int>&changes){


    // calculate for this
    int pos = lower_bound(lis.begin(),lis.end(),arr[node])-lis.begin();
    changes.push(lis[pos]);
    lis[pos] = arr[node];
    ans[node] = max(pos,ans[par]);

    for(int nxt: adj[node]){
        if(nxt!=par){
            dfs(nxt,node,lis,changes);
        }
    }


    int temp = changes.top(); changes.pop();
    lis[pos] = temp;
}

int main(){

    FASTIO;
    PRECISION;

    int n;
    cin>>n;

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

    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<int>lis(n+1,inf);
    stack<int>changes; // value at position 0 changes from 1 to 2
    lis[0] = -inf;
    dfs(1,0,lis,changes);

    for(int i=1;i<=n;i++){
        cout<<ans[i]<<"\n";
    }
}


Measured memory_bytes: 31460
#include <iostream>
using namespace std;
int main(void){
    int len;
    string s;
    cin >> s;
    len = s.length();
    for(int i=0;i<len-1;i++){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if(i+2 < len && s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    puts("-1 -1");
}


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

const int MOD = 1e9 + 7;

long long exp_mod(int a, int b, int m) {  // return a^b mod m
    long long ans = 1;
    long long tmp = a;
    while (b) {
        if (b & 1) {
            ans = (ans * tmp) % m;
        }
        b >>= 1;
        tmp = (tmp * tmp) % m;
    }
    return ans;
}

long long inv(int a, int m) {  // return a-1
    return exp_mod(a, m - 2, m);
}

long long ncr_mod(int n, int r, int m) {  // return nCr mod m
    long long ret = 1;
    for (int i = 0; i < r; ++i) {
        ret = (ret * (n - i)) % m;
        ret = (ret * inv(1 + i, m)) % m;
    }
    return ret;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    long long ans = exp_mod(2, n, MOD) - 1;
    cout << (ans - ncr_mod(n, a, MOD) - ncr_mod(n, b, MOD) + MOD + MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 384
module queue
  implicit none
  type :: JagArray
    integer,allocatable :: array(:)
  end type JagArray
  contains
  subroutine push(A,b)
  	integer,allocatable,dimension(:)::A
    integer::b
    A=[A,b]
  end subroutine
  subroutine pop(A)
  	integer,allocatable,dimension(:)::A
    A=A(2:)
  end subroutine
end module queue

use queue
integer N,M
integer X,Y
type(JagArray)::EDGE(100000)!ここ、実は意地悪な問題が来ると溢れてしまいます、困った
integer Nindex(100000)
integer DP(100000)
integer ans
!読み込み
read*,N,M
do i=1,100000
EDGE(i)%array= [integer::]
end do
Nindex = 0
do i=1,M
  read*,X,Y
  Nindex(X)=Nindex(X)+1
  EDGE(X)%array=[EDGE(X)%array,Y]
end do
!読み込み終了

DP = -1
!DP[i]とはノードiからのびる経路のうち最短のもの
!まだ調べていない状態は-1とする
ans = 0
do i=1,N
  if( DP(i)== -1)DP(i)=DFS(i)
  ans=max(ans,DP(i) )
end do

print"(I0)",ans

contains

recursive function DFS(u)result(res)
integer u,res

if(DP(u) >= 0)then
  res=DP(u)
else
  DP(u)=0
  do j=1,Nindex(u)
    DP(u)=max(DP(u),DFS(EDGE(u)%array(j))+1)
  end do
  res=DP(u)
endif
end function DFS
end

Measured memory_bytes: 10880
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N,M,S;
    while(1){
        int fie[51][3002]={0};
        cin>>N>>M>>S;
        if(N==0&&M==0&&S==0)break;
        fie[0][0]=1;
        for(int i=1;i<=M;i++){
            for(int j=N*N;0<=j;j--){
                for(int k=S;0<=k;k--){
                    if(k+i<=3000)fie[j+1][k+i]+=fie[j][k];
                    fie[j][k]%=100000;
                }
            }
        }

        cout<<fie[N*N][S]%100000<<endl;
    }
    return 0;
}

Measured memory_bytes: 1764
#include<stdio.h>


int main(){
	int n;
	int count;
	int i,c;
	scanf("%d",&n);

	while(n!=0){
		i=c=count=0;
		for(i=0;i<n/4;i++){
			scanf("%d",&c);
			count=count+c;
		}
		printf("%d\n",count);

		scanf("%d",&n);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	int N;
	cin>>N;
	long long result=0;
	for(int i=1; i<=N; i++)
	{
		if(i%3==0 || i%5==0)
		{
			continue;
		}
		result += i;
	}
	cout<<result<<endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main (void)
{
    int sum[1000];
    int i;
    int j;
    int k=0;
    char array[1000];
    char n[10]={'0','1','2','3','4','5','6','7','8','9'};
        for(i=0;i<1000;i++){
    sum[i]=0;
    }
    while(1){
        for(i=0;i<1000;i++){
    array[i]='0';
    }
    scanf("%s",array);
        if(array[0]=='0'){
            break;
        }
    for(i=0;i<1000;i++){
        for(j=0;j<10;j++){
            if(n[j]==array[i]){
                sum[k]+=j;
            }
        }
    }
    k++;
    }
     
    for(i=0;i<=k;i++){
        if(sum[i]==0){
            break;
        }
    printf("%d\n",sum[i]);
    }
    return 0;
}   

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

int main(void){
	int c[3][3];
	int sum = 0;
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			cin >> c[i][j];
		}
	}
	int a[3], b[3];
	a[0] = 0;
	for(int i = 0; i < 3; ++i){
		b[i] = c[0][i];
	}
	for(int i = 0; i < 3; ++i){
		a[i] = c[i][0] - b[0];
	}
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			if(a[i]+b[j] != c[i][j]){
				cout << "No" <<  endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	scanf("%d%d", &n, &k);
	vi ps(n+1);
	map<int,vi> cnt;
	cnt[0].push_back(0);
	ll answer = 0;
	// can not combine the following 2 for loops. WHY?
	for (int i = 1; i <= n; i++) {
		scanf("%d", &ps[i]);
		ps[i] = (ps[i] + ps[i-1]) % k;
	}

	for (int i = 1; i <= n; i++) {
		ps[i] = (ps[i] + k - (i%k)) % k;
		cnt[ps[i]].push_back(i);
	}

	for (auto& x : cnt) {
		vi& v = x.second;
		int m = v.size();
		for (int i = 0, j = 0; i < m; i++) {
			while (j < m && v[j] - v[i] < k) j++;
			answer += j - i - 1;
		}
	}
	printf("%lld\n", answer);
}


Measured memory_bytes: 22912
N = int(input())
max_num = N
max_count = 0
for i in range(1,N+1):
    if i%2 != 0:
        continue
    j = i
    count = 0
    while j%2 == 0:
        count += 1
        j //= 2
    if max_count < count:
        max_count = count
        max_num = i
print(max_num)

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


int main(){
  int N, L;
  cin >> N >> L;
  vector<int> A(N);
  int ans = 0;
  for(int ii=0; ii<N; ii++){
    A[ii] = L+ii;
    ans += A[ii];
  }
  if(A[N-1] <= 0){
    ans -= A[N-1];
  }else if(A[0]<=0){
  }else{
    ans -= A[0];
  }
  cout << ans << endl;
  return 0;
}


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

#define MAX_N 1120
#define MAX_K 14

int main(){
  bool p[MAX_N+1];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for(int i = 2 ; i*i <= MAX_N ; i++){
    if(p[i]){
      for(int j = i*i ; j <= MAX_N ; j += i){
	p[j] = false;
      }
    }
  }
  vector<int> prime;
  for(int i = 0 ; i <= MAX_N ; i++){
    if(p[i]) prime.push_back(i);
  }
  
  int dp[MAX_K+1][MAX_N+1]; // dp[テァツエツ?ヲツ閉ーテ」ツ?ョテヲツ閉ー][テ・ツ青暗ィツィツ? = テ、ツスツ陛ゥツ?堙」ツつ?
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for(int i = 0 ; i < prime.size() ; i++){ // テ、ツスツソテ」ツ??ァツエツ?ヲツ閉ー
    for(int j = MAX_N ; j >= prime[i] ; j--){ // テ・ツ陳古」ツ?ョテ・ツ青暗ィツィツ?
      for(int k = 14 ; k > 0 ; k--){ // テ、ツスツソテ」ツ?」テ」ツ?淌ァツエツ?ヲツ閉ーテ」ツ?ョテヲツ閉ー 
	dp[k][j] += dp[k-1][j - prime[i]];
      }
    }
  }

  int n, m;
  while(cin >> n >> m, n|m){
    cout << dp[m][n] << endl;
  }
  return 0;
}

Measured memory_bytes: 1288
#include<stdio.h>

int main(){
  
  int A,B,T,i=0;
  scanf("%d %d %d",&A,&B,&T);
  for(i=0;i<21;i++)
    if(A*i>T+0.5)
      break;
  printf("%d",B*(i-1));
  
}

Measured memory_bytes: 128
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	long long x, y;
	cin >> x >> y;
	if (x < y)swap(x, y);
	if (x == y) {
		cout << "Brown" << endl;
		return 0;
	}
	if ((x - y) % 3 == 0) {
		cout << "Alice" << endl;
		return 0;
	}
	if ((x - y) >= 2) {
		cout << "Alice" << endl;
		return 0;
	}
	else {
		cout << "Brown" << endl;
		return 0;
	}
}

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

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

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

  int total = 0;
  rep(i,n) {
    int x;
    cin >> x;
    total += x;
  }
  if (total >= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
int desc(const void *x, const void *y){
    return *(int *)x - *(int *)y;
}
int main(void){
    int n,i,j,k,cnt=0;
    scanf("%d",&n);
    int l[n];
    for(i=0;i<n;i++) scanf("%d",&l[i]);
    qsort(l,n,sizeof(int),desc);
    for(i=0;i<n;i++){
        for(j=0;j<i;j++){
            for(k=0;k<j;k++){
                if(l[i]!=l[j] && l[j]!=l[k] && l[k]+l[j]>l[i]) cnt++;
            }
        }
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 1732
s, t = (input() for _ in range(2))
new_s = ''.join(sorted(s))
new_t = ''.join(sorted(t, reverse = True))
lst = sorted([new_s, new_t])
if lst.index(new_s) == 1 or new_s == new_t:
    print('No')
else:
    print('Yes')

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

int main(void) {
  int line = 0;
  string s;
  bool flag;
  while (cin >> s) {
    flag = true;
    for (int i = 0; i < s.size()/2; i++) {
      if (s[i] != s[s.size()-1-i]) {
        flag = false;
        break;
      }
    }

    if (flag) {
      line++;
    }
  }

  cout << line << endl;

  return 0;
}

Measured memory_bytes: 1188
N = int(input())
h = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(h[1] - h[0])

if N >= 3:
    for i in range(2,N):
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]))
print(dp[N-1])

Measured memory_bytes: 13900
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 2e4 + 5;
char s[maxn], t[maxn];
int n, ps[maxn], pt[maxn], cs, ct, ans = 1 << 30, nans;
int tmps[maxn], tmpt[maxn];

int GetAns(int x) {
	int r = max(x + cs, ct), ts = 0;
	int l = min(x, 0), tt = 0, nans = 0;
	for(register int i = l; i < r; ++i) {
		if(i >= x && i < x + cs) tmps[++ts] = ps[i - x];
		if(i < x) tmps[++ts] = -1;
		if(i >= x + cs) tmps[++ts] = n - 1;
		if(i >= 0 && i < ct) tmpt[++tt] = pt[i];
		if(i < 0) tmpt[++tt] = -1;
		if(i >= ct) tmpt[++tt] = n - 1;
	}
	for(register int i = 1; i <= ts; ++i) {
		nans += abs(tmps[i] - tmpt[i]);
	}
	return nans;
}

int main() {
	scanf("%d", &n);
	scanf("%s%s", s, t);
	if(s[0] == '0') ps[cs++] = -1;
	if(t[0] == '0') pt[ct++] = -1;
	for(register int i = 0; i < n - 1; ++i) {
		if(s[i] != s[i + 1]) ps[cs++] = i;
		if(t[i] != t[i + 1]) pt[ct++] = i;
	}
	for(register int i = -cs; i <= ct; ++i) {
		if(abs(i) & 1) continue;
		ans = min(ans, GetAns(i));
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int i, j, k;
	int sum;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	i = atoi(ch);
	ch = strtok(NULL, " ");
	j = atoi(ch);
	ch = strtok(NULL, " ");
	k = atoi(ch);

	sum = 100 * i + 10 * j + k;

	if(sum % 4 == 0) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 2004
n, m = map(int, input().split())
if m == 0:
  print('0 0')
  exit()
acornot = [False] * n
walst = [0] * n
acsum = 0
for i in range(m):
  subnum, res = input().split()
  subnum = int(subnum) - 1
  if acornot[subnum] == False:
    if res == 'AC':
      acornot[subnum] = True
      acsum += 1
    else:
      walst[subnum] += 1
for i in range(n):
  if acornot[i] == False:
    walst[i] = 0
print(acsum, sum(walst))

Measured memory_bytes: 10360
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

bool compare_by_second(pair<int, int> a,pair<int, int> b)
{
    if(a.first != b.first){
        return a.first > b.first;
    }else{
        return a.second < b.second;
    }    
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> day(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        day[i]=make_pair(a,b);
    }
    sort(day.begin(),day.end());
    //for(int i=0;i<n;i++){
        //cout << day[i].first << day[i].second << endl;
    //}
    int ans=0;
    int j=0;
    priority_queue<int> que;
    for(int i=0;i<=m;i++){
        while(true){
            if(j==n) break;
            if(day[j].first<=i){
                que.push(day[j].second);
            }else{
                break;
            }
            j++;
        }
        if(que.size()>0){
            ans+=que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1660
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
ans = int(0)

N, M = LI()
S = LI()
T = LI()
dp = [[0]*(M+1) for _ in range(N+1)]
sumdp = [[0]*(M+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = sumdp[i-1][j-1]+1
            sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1
#            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] + dp[i][j]
        #累積和の更新
        else:
            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %=mod
#        ans += dp[i][j]
#print(dp)
#for row in dp:
#    ans+= sum(row)%mod
print((sumdp[N][M]+1)%mod)

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

int main() {
  string s;
  cin>>s;
  if(s=="hi"){
    cout<<"Yes"<<endl;
  }
  else if(s=="hihi"){
    cout<<"Yes"<<endl;
  }
  else if(s=="hihihi"){
    cout<<"Yes"<<endl;
  }
  else if(s=="hihihihi"){
    cout<<"Yes"<<endl;
  }
  else if(s=="hihihihihi"){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

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

using namespace std;

int N;
vector<int> vec;
vector<int> sorted;
void solve();

int main() {
  cin >> N;
  vec.resize(N);
  sorted.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
    sorted[i] = vec[i];
  }
  sort(sorted.begin(), sorted.end());
  solve();
}

void solve() {
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (vec[i] != sorted[i]) {
      count++;
    }
  }
  string ans = count <= 2 ? "YES" : "NO";
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans = 0;
		for(int i=1;i<N+1;i++) {
			for(int j=1;j<N+1;j++) {
				for(int k=1;k<N+1;k++) {
					int gcd = gcd(i,j);
					gcd = gcd(gcd,k);
					ans += gcd;
//					System.out.println(i);
//					System.out.println(j);
//					System.out.println(k);
				}
			}
		}
		System.out.println(ans);
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }

}



Measured memory_bytes: 35872
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const int MAXN = 3e3 + 10 ; 
string s , t ;
int n , m; 
int dp[MAXN][MAXN] ; 
int dfs(int x,int y){
	if ( x == n || y == m ) return 0 ; 
	if ( dp[x][y] != -1 ) return dp[x][y] ; 
	int choice1 = 0 ; 
	int choice2 = 0 ; 
	if ( s[x] == t[y] ) {
		choice1 = 1 + dfs(x+1,y+1) ; 
	}
	else{
		choice1 = dfs(x+1,y) ; 
		choice2 = dfs(x,y+1) ; 
	}
	return dp[x][y] = max(choice1,choice2) ; 
}
void build(int x,int y){
	if ( x == n || y == m ) return ; 
	int choice1 = 0 ; 
	int choice2 = 0 ; 
	int choice3 = 0 ; 
	if ( s[x] == t[y] ) {
		choice1 = 1 + dfs(x+1,y+1) ; 
	}
	else{
		choice2 = dfs(x+1,y) ; 
		choice3 = dfs(x,y+1) ; 
	}
	int optimal = dfs(x,y) ; 
	if ( optimal == choice2 ){
		build(x+1,y) ; 
	}
	else if ( optimal == choice3 ){
		build(x,y+1) ; 
	}
	else if ( optimal == choice1 ){
		cout << s[x] ; 
		build(x+1,y+1) ; 
	}
}
int main(){
    fastio
    memset(dp,-1,sizeof dp) ; 
    cin >> s >> t ; 
    n = (int) s.size() ; 
    m = (int) t.size() ; 
    dfs(0,0);
    build(0,0); 
    return 0 ;
}


Measured memory_bytes: 36096
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}


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

if m2 >= m1
  total = (h2 - h1) * 60 + (m2 - m1)
else
  total = (h2 - h1 - 1) * 60 + (60 + m2 - m1)
end

puts total - k

Measured memory_bytes: 14524