akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int A;
	long double B;
	cin>>A>>B;
	int C=A*((int)(B/1));
	long double D=A*(B-((int)(B/1)));
	long double E=C+D;
	int F=E;
	cout<<F<<endl;
}

Measured memory_bytes: 3704
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define F first
#define S second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

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

int main(void){
    for(int w, h, res; cin >> h >> w; cout << res << endl){
        res = 0;

        map<char, vector<pii> > m;

        vs field(h);
        rep(y, h){
            cin >> field[y];
            rep(x, w) if(field[y][x] != '.') m[field[y][x]].pb(mp(y, x));
        }

        bool end = false;
        while(!end){
            end = true;

            rep(y, h){
                rep(x, w){
                    if(field[y][x] != '.') continue;

                    set<char> s;

                    rep(i, 4){
                        range(k, 1, 1000){
                            pii next = mp(y + k * dy[i], x + k * dx[i]);
                            if(next.F < 0 || h <= next.F || next.S < 0 || w <= next.S) break;

                            char c = field[next.F][next.S];
                            if(c != '.'){
                                if(!s.insert(c).S){
                                    rep(j, 2) field[m[c][j].F][m[c][j].S] = '.';
                                    res += 2;
                                    end = false;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1500
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S;
int num[30];

signed main(){
	cin>>S;
	int N=S.size();
	int cnt=0;
	REP(i,N){
		num[S[i]-'a']++;
		cnt++;
	}
	if(cnt<26){
		REP(i,26){
			if(num[i]==0){
				S+=char('a'+i);
				cout<<S<<endl;
				return 0;
			}
		}
	}
	else{
		for(int i=0;i<=N-1;i++){
			bool flag=true;
			for(int j=i;j<=N-1;j++){
				if(S[j]<S[j+1]){
					flag=false;
				}
			}
			if(flag==false)continue;
			if(i==0){
				cout<<-1<<endl;
				return 0;
			}
			else{
				string t;
				vector<char> v;
				for(int j=0;j<=i-2;j++){
					t+=S[j];
				}
				for(int j=i;j<=N-1;j++){
					if(S[i-1]<S[j]){
						v.push_back(S[j]);
					}
				}
				sort(v.begin(),v.end());
				cout<<t+v[0]<<endl;
				return 0;
			}
		}
	}
	return 0;
}


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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  char a;
  cin >> a;
  if('a' <= a && a <= 'z'){
    cout << 'a' << endl;
  }
  else{
    cout << 'A' << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s.at(k - 1) = s.at(k - 1) + ('a' - 'A');
	cout << s << endl;
		
}

Measured memory_bytes: 3604
#!/usr/bin/python

import sys

itoa = {
	 1:'a', 2:'b', 3:'c', 4:'d', 5:'e',
	 6:'f', 7:'g', 8:'h', 9:'i',10:'j',
	11:'k',12:'l',13:'m',14:'n',15:'o',
	16:'p',17:'q',18:'r',19:'s',20:'t',
	21:'u',22:'v',23:'w',24:'x',25:'y',
	26:'z'
}

atoi = {
	'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5,
	'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j':10,
	'k':11, 'l':12, 'm':13, 'n':14, 'o':15,
	'p':16, 'q':17, 'r':18, 's':19, 't':20,
	'u':21, 'v':22, 'w':23, 'x':24, 'y':25,
	'z':26
}

def main():
	for crypt in sys.stdin:
		for i in xrange(1, 27):
			decrypt = decryptor(crypt.strip(), i)
			if (decrypt.find('the') != -1
				or decrypt.find('this') != -1
				or decrypt.find('that') != -1):
				print decrypt
				break

def decryptor(crypt, offset):
	global atoi
	global itoa

	decrypt = ''

	for c in crypt:
		if (c == ' ' or c == ',' or c == '.' or c == "\n"):
			decrypt += c
		else:
			code = atoi[c]
			code -= offset
			if (code <= 0 ):
				code = 26 + code

			decrypt += str(itoa[code])

	return decrypt

main()

Measured memory_bytes: 4300
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
#define rep(x,y) for(x=0;x<(y);++x)
typedef pair<int, int> P;
const int MAX_N=1011;//提交之前改成1011
const int dw[4]={1,0,-1,0},dh[4]={0,1,0,-1};
const char sdt='S',vac='.',blc='X',hdns[11]={'0','1','2','3','4','5','6','7','8','9'};
void in();
void solve();
void bfs(char g);
int H,W,N;//高，&#23485;，目&#26631;数
int sh,sw;//起始位置
int cdis;//当前&#26102;&#38388;
char maze[MAX_N][MAX_N];//地&#22270;,h-第一&#32500;，w-第二&#32500;，从1&#24320;始
int dis[MAX_N][MAX_N];//距&#31163;&#26631;&#35760;

int main()
{
	in();
	solve();
	return 0;
}
void in()
{
	cin>>H>>W>>N;
	int h,w;
	for(h=1;h<=H;++h)
	{
		for(w=1;w<=W;++w)
		{
			cin>>maze[h][w];
			if(sdt==maze[h][w])
			{
				sh=h;
				sw=w;
			}
		}
	}
}
void solve()
{
	int n;
	int tm=0;
	for(n=1;n<=N;++n)
	{
		memset(dis,-1,sizeof(dis));//&#27599;一次都重新&#35774;置起始&#32456;止点，重新&#26631;&#35760;距&#31163;
		bfs(hdns[n]);
		tm+=cdis;
	}
	cout<<tm<<endl;
}
void bfs(char g)
{
	queue<P> que;
	P nl=P(sh,sw);
	int ch,cw;
	que.push(nl);
	dis[sh][sw]=0;
	int i,ndis;
	while(1)//一定会找到的，不用写que.size()
	{
		nl=que.front();
		que.pop();
		ndis=dis[nl.first][nl.second];
		rep(i,4)
		{
			ch=nl.first+dh[i];
			cw=nl.second+dw[i];
			if(!(H<ch||ch<1||W<cw||cw<1||blc==maze[ch][cw]||-1!=dis[ch][cw]))
			{
				if(g==maze[ch][cw])
				{
					cdis=ndis+1;
					sh=ch;
					sw=cw;
					return;
				}
				que.push(P(ch,cw));
				dis[ch][cw]=ndis+1;
			}
		}
	}
FIND:
	return;
}

Measured memory_bytes: 6208
#include <iostream>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  
  for (int i = 1; i <= 9; i++)
  {
    for (int j = 1; j <= 9; j++)
    {
      if (i * j == n)
      {
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  
  cout << "No" << endl;
  return 0;
}

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

int nnex[200001];
int ppex[200001];
int main(){
  int N,M,Q;
  cin >> N >> M >> Q;
  int bat = 0;
  for(int i=0; i < N; i++){
    nnex[i] = (i + 1)%N;
    ppex[i] = (i - 1 + N) % N;
  }
  for(int i = 0; i < M ; i++){
    int a;
    cin >> a;
    for(int j = 0; j < a; j++){
      if(a%2 == 0){
	bat = nnex[bat];
      }else{
	bat = ppex[bat];
      }
    }
    
    int temp = bat;
    nnex[ppex[bat]] = nnex[bat];
    ppex[nnex[bat]] = ppex[bat];
    bat = nnex[bat];
    nnex[temp] = -1;
    ppex[temp] = -1;
  }
 
  //for(int i = 0; i < N; i++)cout << i << ": " <<nnex[i] << endl; 
  for(int i = 0; i < Q; i++){
    int q;
    cin >> q;
    if(nnex[q] == -1){
      cout << "0" << endl;
    }else{
      cout << "1" << endl;
    }
  }
}




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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int p, q, r;
  if(a > b){
    p = a;
    q = b;
  }
  else{
    p = b;
    q = a;
  }
  while(p % q != 0){
    r = q;
    q = p % q;
    p = r;
  }
  r = q;
  q = p % q;
  p = r;
  int c = 0, t;
  for(int i = 1; i <= p; i++){
    if(p % i == 0)
      c++;
    if(c == k){
      t = p / i;
      break;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
struct edge{
  int from,to,cost;
  edge(){}
  edge(int from,int to,int cost):from(from),to(to),cost(cost){}
  bool operator<(const edge& e) const{
    return cost<e.cost;
  }
};
int kruskal(int N,vector<edge> edges){
  int res=0;
  sort(edges.begin(),edges.end());
  UnionFind uf(N+1);
  for(int i=0;i<(int)edges.size();i++){
    edge e=edges[i];
    if(!uf.same(e.from,e.to)){
      res+=e.cost;
      uf.unite(e.from,e.to);
    }
  }
  return res;
}
int main(){
  int N,M;
  cin>>N>>M;
  vector<edge> edges(M);
  for(int i=0;i<M;i++)
    cin>>edges[i].from>>edges[i].to>>edges[i].cost;
  cout<<kruskal(N,edges)<<endl;
  return 0;
}

Measured memory_bytes: 5220
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(int(len(v)/2))
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Measured memory_bytes: 20572
str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new()
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
	matrix[0][i] = i
end
for i in 1..lenStr2 do
	matrix[i][0] = i
end
for i in 1..lenStr1 do
	for j in 1..lenStr2 do
		x = (str1[i-1] == str2[j-1]) ? 0 : 1
		y = matrix[j][i-1] + 1
		z = matrix[j-1][i] + 1
		matrix[j][i] = [matrix[j-1][i-1]+x, y, z].min
	end
end
print("#{matrix[lenStr2][lenStr1]}\n")

Measured memory_bytes: 20536
using System;
using static System.Console;

namespace brackjack
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ss = ReadLine().Split(' ');
            if(int.Parse(ss[0]) + int.Parse(ss[1]) + int.Parse(ss[2]) <= 21){
                WriteLine("win");
                return;
            }else{
                WriteLine("bust");
                return;
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
using namespace std; 
 


int main() {
    ll a,b,x;
    cin>>a>>b>>x;
    ll fa=((a-1)!=-1 ? ((a-1)/x)+1:0),fb=(b/x)+1;
    ll ans=fb-fa;
    // cout<<"fa: "<<fa<<endl<<"fb: "<<fb<<endl;
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R = sc.nextInt();
		if (N < 10) {
			int keisan = 100 * (10 - N);
			System.out.println(keisan + R);
		} else {
			System.out.println(R);
		}
		sc.close();
	}
}

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

using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
#define re return
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)a.size()
typedef long long ll;

const ll mod = 1e9 + 7;
ll n, ans[100001];
vector<pair<ll, ll> > a;

int main() {
	iostream::sync_with_stdio(0);
	//freopen("a.in", "r", stdin);
	cin >> n;
	a.resize(n);
	forn (i, n) {
		cin >> a[i].fi;
		a[i].se = i;
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	ll mi = n;
	a.push_back(mp(0, 0));
	forn (i, n) {
		mi = min(mi, a[i].se);
		ans[mi] += (a[i].fi - a[i + 1].fi) * ll(i + 1);
	}
	forn (i, n)
		cout << ans[i] << "\n";
}	

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b;
  long long k;
  cin>>a>>b>>k;
  if(a-k<0){
    cout<<0<<" ";
  }else{
    cout<<a-k<<" "<<b<<"\n";
    return(0);
  }
  k-=a;
  if(b-k<0){
    cout<<0<<"\n";
  }else{
    cout<<b-k<<"\n";
  }
  return(0);
}


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

int main()
{
    double dx, dy, d;
    double c1x, c1y, c1r, c2x, c2y, c2r;
    scanf("%lf %lf %lf %lf %lf %lf", &c1x, &c1y, &c1r, &c2x, &c2y, &c2r);
    dx = c1x - c2x;
    dy = c1y - c2y;
    d = sqrt(dx * dx + dy * dy);
    if(d > c1r + c2r){ printf("4\n"); }
    else if(d == c1r + c2r){ printf("3\n"); }
    else{
        if(c1r < c2r) swap(c1r, c2r);
        if(d > c1r - c2r){ printf("2\n"); }
        else if(d == c1r - c2r){ printf("1\n"); }
        else{ printf("0\n"); }
    }

    return 0;
}

Measured memory_bytes: 1192
a, b, m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
xyc = [map(int, input().split()) for _ in range(m)]

discount = min(aa[x-1] + bb[y-1] - c for x, y, c in xyc)
cheap = min(aa) + min(bb)

print(min(discount, cheap))

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

int main(){
	string s;
	cin>>s;
	if(s[s.size()-1]=='s'){
		s = s +"es";
		//s[s.size()-2] = 'e';
	}
	else{
		s = s + 's';
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3620
# include<stdio.h>
# include<math.h>

int main(){

  int h,v,X,Y;
  double x,y,t,r,e;

  x=0,y=0,t=0,r=0;
  e = 2*M_PI / 360;
  while(1){
    scanf("%d,%d",&h,&v);
    if(h==0 && v==0)break;
    x = x + (h*cos((90-r) * e));
    y = y + (h*sin((90-r) * e));
    r = r + v;
  }
  X = floor(x);
  Y = ceil(y);
  printf("%d\n",X);
  printf("%d\n",Y);

  return 0;
}

Measured memory_bytes: 608
package main
 
import (
  "fmt"
)
 
func main() {
  var a, b int
  fmt.Scan(&a, &b)
  if a % 2 == 0 || b % 2 == 0 {
    fmt.Println("Even")
  } else {
    fmt.Println("Odd") 
  }
}

Measured memory_bytes: 512
a, b = map(int, input().split())
c = 0
lst = []

for i in range(1, 1000):
    c += i
    lst.append(c)


for i in range(999):
    if lst[i]>a and lst[i+1]>b and lst[i]-a==lst[i+1]-b:
        print(lst[i]-a)
        break

Measured memory_bytes: 3060
// AOJ 0282: Programming Contest
// 2017.8.19 bal4u@uu
// 2017.11.25

#include <stdio.h>

#define QSIZE 1000000
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { int id, key, c; } QUE;
QUE que[QSIZE+5]; int qsize;

void max_heapify(int i)
{
	int l, r, max;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && (que[l].key > que[i].key || (que[l].key == que[i].key && que[l].id < que[i].id)))
		max = l;
	else max = i;
	if (r < qsize && (que[r].key > que[max].key || (que[r].key == que[max].key && que[r].id < que[max].id)))
		max = r;
	if (max != i) {
		QUE t = que[i]; que[i] = que[max], que[max] = t;
		max_heapify(max);
	}
}

void deq(void)
{
//	if (qsize == 0) return;
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(void)
{
	int i, max;
	i = qsize++;
	while (i > 0 && (que[max = PARENT(i)].key < que[i].key
		|| (que[max].key == que[i].key && que[max].id > que[i].id))) {
		QUE t = que[i]; que[i] = que[max], que[max] = t;
		i = max;
	}
}

#define MAX 100002
int x[MAX], t[MAX], c[MAX];
char buf[102], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int N, R, L, d, tt;
	int lt, ld, i, ans;

	fgets(p=buf, 100, stdin), N = getint(), p++, R = getint(), p++, L = getint();
	qsize = 0; lt = 0, ld = 1;
	que[0].id = 1, que[0].key = 0, que[0].c = 1, enq();
	x[1] = 0, c[1] = 1;
	while (R--) {
		fgets(p=buf, 100, stdin), d = getint(), p++, tt = getint(), p++;
		if (*p == '-') p++, x[d] -= getint(); else x[d] += getint();
		c[d]++;
		que[qsize].id = d, que[qsize].key = x[d], que[qsize].c = c[d];
		enq();

		while (1) {
			d = que[0].id;
			if (c[d] == que[0].c) {
				t[ld] += tt - lt;
				lt = tt, ld = d;
				break;
			}
			deq();
		}
	}
	t[ld] += L - lt;
	for (tt = 0, i = 1; i <= N; i++) if (t[i] > tt) tt = t[i], ans = i;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9304
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

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


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> sum(n, 0);
  for(int i = 1; i < sz(s); i++){
    sum[i] = sum[i-1];
    if(s[i-1] == 'A' && s[i] == 'C')sum[i] += 1;
  }
  rep(i, q){
    int l, r;
    cin >> l >> r, l--, r--;
    int res = sum[r];
    res -= sum[l];
    cout << res << endl;
  }
	return 0;
}


Measured memory_bytes: 1616
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    vector<vector<int>> dp(3,vector<int>(n));
    F0R(i,n)
        cin >> a[i] >> b[i] >> c[i];
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    FOR(i,1,n)
    {
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
        dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c[i];
    }
    cout << max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) << endl;

    return 0;
}


Measured memory_bytes: 2944
n = int(input())
a = [[] for i in range(n)]

for i in range(n):
    v = list(map(int, input().split()))
    u = v[0] - 1
    for j in v[2:]:
        a[u].append(j-1)

d = [0] * n
f = [0] * n
isDiscovered = [False] * n
time_stamp = 0

def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp += 1
    d[x] = time_stamp
    for i in a[x]:
        if not isDiscovered[i]:
            dfs(i)
    time_stamp += 1
    f[x] = time_stamp

for i in range(n):
    if not isDiscovered[i]:
        dfs(i)

for i in range(n):
    print(i+1, d[i], f[i])

Measured memory_bytes: 5656
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#include <iomanip>
#define lsb(x) ((x) & -(x))
using namespace std;

typedef long long i64;

const int NMAX = 16;
i64 cost_comp[1 << NMAX];
i64 dp[1 << NMAX];
int cost[NMAX][NMAX];

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

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            scanf("%d", cost[i] + j);

    for (int mask = 0; mask < (1 << n); mask++)
        for (int i = 0; i < n; i++)
            if (mask & (1 << i))
                for (int j = i + 1; j < n; j++)
                    if (mask & (1 << j))
                        cost_comp[mask] += cost[i][j];

    for (int mask = 0; mask < (1 << n); mask++)
        for (int c = mask; c; c = (c - 1) & mask)
            dp[mask] = max(dp[mask], cost_comp[c] + dp[mask ^ c]);

    cout << dp[(1 << n) - 1] << '\n';

    return 0;
}


Measured memory_bytes: 1280
n = int(input())
b = list(map(int, input().split()))

a = [0]*n

if n == 2:
  print( 2* b[0])
  exit()

for i in range(1,n-1):
  a[i] = min(b[i-1], b[i])

a[0] = b[0]  
a[n-1] = b[n-2]
    
sum = 0

for i in range(n):
  sum += a[i]
  
print(sum)

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

int di[4] = {0,1,0,-1};
int dj[4] = {1,0,-1,0};
#define inRange(x,a,b) (a <= x && x < b)

struct UF{
    vector<int> p;
    int n;

    UF(int siz){
        n = siz;
        p.resize(n, 0);
        for(int i = 0; i < n; i++)  p[i] = i;
    }

    int parent(int x){
        if(p[x] != x)   p[x] = parent(p[x]);
        return p[x];
    }

    bool same(int x, int y){
        return parent(x) == parent(y);
    }
    
    void unite(int x, int y){
        x = parent(x), y = parent(y);
        p[x] = y;
    }
};

int main(){
    int w, h;
    cin >> w >> h;
    int ti, tj;
    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
            if(mat[i][j] == 't')    ti = i, tj = j;
        }
    }
    UF uf(w*h);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] == '#')    continue;
            for(int k = 0; k < 2; k++){
                int ni = i+di[k], nj = j+dj[k];
                if(inRange(ni,0,h)&&inRange(nj,0,w)&&mat[ni][nj]!='#'){
                    uf.unite(i*w+j, ni*w+nj);
                }
            }
        }
    }
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++){
        if(uf.same(0, ti*w+tj)){
            cout << i << endl;
            return 0;
        }
        if(i == n)  break;
        int si, sj;
        cin >> sj >> si;
        mat[si][sj] = '.';
        for(int k = 0; k < 4; k++){
            int ni = si+di[k], nj = sj+dj[k];
            if(inRange(ni,0,h)&&inRange(nj,0,w)&&mat[ni][nj]!='#'){
                uf.unite(si*w+sj, ni*w+nj);
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 7736
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

#define X first
#define Y second

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;

const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};

string mp[505];
char ans[505][505]={};
int h[505]={};
bool b[505][505]={};
void dfs(int x, int y){
	chmax( h[x], y );
	ans[y][x] = '#';
	b[y][x] = true;
	rep(i,4){
		int nx = x + vx[i];
		int ny = y + vy[i];
		if( b[ny][nx] ) continue;
		if( mp[ny][nx] == '#' ){
			dfs( nx, ny );
		}
	}
}

int main(){
	int H, W;

	cin >> H >> W;
	rep(y,H) cin >> mp[y];

	Fill(ans, '.');
	rep(i,W-2) ans[0][i+1] = '#';
	for(int x=1; x<W-1; x++){
		for(int y=1; y<H-1; y++){
			if( mp[y][x] == '#' && !b[y][x] ){
				for(int _y=y-1; ans[_y][x]=='.' && ans[_y+1][x-1]=='.'; _y--){
					ans[_y][x] = '#';
				}
				dfs( x, y );
			}
		}
	}

	// output
	rep(y,H){
		rep(x,W){
			cout << ans[y][x];
		}
		cout << endl;
	}
	cout << endl;
	rep(y,H){
		rep(x,W){
			char out = ans[y][x]=='#'?'.':'#';
			if(mp[y][x] == '#') out = '#';
			cout << out;
		}
		cout << endl;
	}

	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    ld ans = 0.;
    rep(i, N)
    {
        double x;
        cin >> x;
        string v;
        cin >> v;
        if (v == "JPY")
        {
            ans += x;
        }
        else
        {
            ans += x * 380000.0;
        }
    }
    cout << setprecision(10) << fixed << ans << endl;
    return 0;
}

Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer :: n,a,b,m

read(*,*) n,a,b    !ここが入力欄

if (a+b-n <= 0) then
    m = 0
else
    m = a+b-n
end if

print'(i0," ",i0)', min(a,b),m

END PROGRAM ATCODER

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef long long int lli;
int main(void)
{
  int n;
  lli i=0;
  lli cnt=0,sum=0;
  
  scanf("%d",&n);
  while(cnt<n){
    i++;
    if(i%3!=0&&i%5!=0){
      sum+=i;
    }
    cnt++;
  }
  printf("%lld\n",sum);
  return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#define mt(a) memset(a,0,sizeof(a))
#define MAXN 1000+10
#define ll long long
const ll INF = 0x3f3f3f3f;
using namespace std;
int main (void)  
{   
	int a,b;
	cin>>a>>b;
	int sum = a;
	if(b<a)
		sum--;
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

const int inf = (int) 1e9;

inline void get(int& v) {
  int ch = getchar();
  while (ch < '0' || ch > '9') {
    ch = getchar();
  }
  v = 0;
  while ('0' <= ch && ch <= '9') {
    v = v * 10 + ch - 48;
    ch = getchar();
  }
}

struct point {
  int x;
  int y;
  int h;
};

signed main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  get(n);
  vector<point> p(n);
  for (int i = 0; i < n; ++i) {
    get(p[i].x);
    get(p[i].y);
    get(p[i].h);
  }
  for (int cx = 0; cx <= 100; ++cx) {
    for (int cy = 0; cy <= 100; ++cy) {
      int low = 1, high = (int) 2e9;
      auto check = [&](int k) {
        for (int i = 0; i < n; ++i) {
          int alt = max(0LL, k - abs(p[i].x - cx) - abs(p[i].y - cy));
          if (alt < p[i].h) {
            return -1;
          } else if (alt > p[i].h) {
            return 1;
          }
        }
        return 0;
      };
      while (low <= high) {
        int mid = (low + high) >> 1;
        int t = check(mid);
        if (t == 0) {
          printf("%lld %lld %lld\n", cx, cy, mid);
          return 0;
        } else if (t == -1) {
          low = mid + 1;
        } else {
          high = mid - 1;
        }
      }
    }
  }
  return 0;
}


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

typedef long long ll;

ll ruijyo(ll a,ll n){
    if(n==0) return 1;
    ll x = ruijyo(a,n/2);
    x = x * x;
    if(n%2==1) x = x * a;
    return x;
}

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

    ll x; cin >> x;
    for(ll i=-1000;i<=1000;i++){
        ll a = ruijyo(i,5);
        for(ll j=-1000;j<=1000;j++){
            ll b = ruijyo(j,5);
            if(a-b==x){
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main() {
    int p[7] = {1, 2, 3, 4, 5, 6, 7};
    int N,M,i,a,b,c=0,x=0;
    cin >> N >> M;
    vector<vector<bool>> e(N, vector<bool>(N,0));

    for(i=0; i<M; i++) {
        cin >> a >> b;
        e.at(a-1).at(b-1) = 1;
        e.at(b-1).at(a-1) = 1;
    }

    do {
        for(i=0; i<N-1; i++) {
            if(!e.at(x).at(p[i]))
                break;
            x = p[i];
        }
        if(i==N-1)
            c++;
        x = 0;
    } while(next_permutation(p, p+N-1));

    cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){
    int x; cin>>x;
    while(true){
        if(IsPrime(x)){
            cout<<x<<endl;
            return 0;
        }
        x++;
    }
}

Measured memory_bytes: 3644
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;


public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] p = new long[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		double[] kitai = new double[n];
		for (int i = 0; i < n; i++) {
			kitai[i] = (p[i] + 1) / 2.0;
		}
		double[] sum = new double[n + 1];
		for (int i = 1; i <= n; i++) {
			sum[i] = sum[i - 1] + kitai[i - 1];
		}
		double max = 0;
		for (int i = k; i <= n; i++) {
			max = Math.max(max, sum[i] - sum[i - k]);
		}
		System.out.println(max);
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

using namespace std;

/**************************************************************/

#define int long long
#define tie() ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i,from,to) for(int i = from ; i <to ; i++)
#define mem(a , v) memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define what_is(x) cerr << #x << " is : " << x <<endl

const int INF = 1e9 + 7;
const int sz = 1e5 + 20;
/***************************************************************/

const int N = 1e5 + 200;
vector <int> g[N];
bool vis[N];
map <pair <int,int> , int> clr;

int c = 0;

void dfs(int x , vector <int> g[] , bool vis[])
{
    vis[x] = true;
    int opt = 0 , ind = 0;
    f(j,0,g[x].size())
    {
        int u = min(x , g[x][j]) , v = max(x , g[x][j]);
        if(clr.find(mp(u,v)) != clr.end())
            opt = clr[mp(u,v)] , ind = j;
    }

    int h = g[x].size();

    //cout<<x<<" "<<ind<<" "<<opt<<endl;
    f(i,0,h)
    {
        ind = (ind+1)%h , opt = (opt+1) % c;
        int u = min(x , g[x][ind]) , v = max(x , g[x][ind]);
        clr.insert(mp(mp(u,v) , opt));
    }

    for(auto node : g[x])
    {
        if(!vis[node])
            dfs(node , g , vis);
    }

    return;
}


void solve()
{
    int n , u , v;cin>>n;
    vector <pair <int,int> > ve;
    f(i,0,n-1)
    {
        cin>>u>>v;
        u-- , v--;
        g[u].pb(v) , g[v].pb(u);
        u = min(u,v);
        v = max(u,v);
        ve.pb(mp(u,v));
    }

    f(i,0,n) c = max(c  , (int)g[i].size());

    cout<<c<<endl;


    dfs(0 , g , vis);
    for(auto node : ve)
    {
        int u = node.ff , v = node.ss;
        cout<<clr[mp(u,v)] + 1<<endl;
    }

    return;
}


int32_t main()
{
    clock_t st = clock();
    tie();
    int t = 1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    clog<<(long double)((clock() - st)/CLOCKS_PER_SEC)<<endl;
    return 0;
}


Measured memory_bytes: 19188
#include <vector>
#include <iostream>
#include <iomanip>

using namespace std;
using ll = long long;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    int n, w;
    cin >> n >> w;
    vector<pair<ll, ll>> in(n);
    for (auto &&a: in) {
        cin >> a.first >> a.second;
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < w + 1; ++j) {
            if (j - in[i].first >= 0) {
                chmax(dp[i + 1][j], dp[i][j - in[i].first] + in[i].second);
            }
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[n][w] << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);

    solve();
    return 0;
}


Measured memory_bytes: 80256
S = input()

if S == "SUN":
    print("7")
elif S == "MON":
    print("6")
elif S == "TUE":
    print("5")
elif S == "WED":
    print("4")
elif S == "THU":
    print("3")
elif S == "FRI":
    print("2")
elif S == "SAT":
    print("1")

Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <set>
#include <map>

#define mod 1000000007
#define mod1 998244353
#define pii 3.14159265358979323846
#define ll long long int
#define array cin>>n;vi arr(n);for(i=0;i<n;i++) cin>>arr[i];
using namespace std;
typedef vector<ll> vi;
typedef vector<char> vc;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
		ll n,q,i,a,b,sum=0;
//		string s;
		vi v1(100001,0);
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>a;
			v1[a]++;
			sum+=a;
		}
		cin>>q;
		for(i=0;i<q;i++)
		{
			cin>>a>>b;
			sum=sum+(b-a)*v1[a];
			v1[b]+=v1[a];
			v1[a]=0;
			cout<<sum<<"\n";
		}
}



Measured memory_bytes: 3848
#include <stdio.h>
#include <limits.h>

const int INF = INT_MAX;

int main(void)
{
	int n, m, a, b, k, t;
	int tcost[105][105], mcost[105][105], node[105], used[105];
	int i, j, min, cost, time;
	
	while (1){
		scanf("%d %d", &n, &m);
		
		if (n == 0 && m == 0){
			break;
		}
		
		for (i = 0; i < m; i++){
			for (j = 0; j < m; j++){
				mcost[i][j] = INF;
				tcost[i][j] = INF;
			}
		}
		
		for (i = 0; i < n; i++){
			scanf("%d %d", &a, &b);
			a--; b--;
			scanf("%d %d", &cost, &time);
			
			if (cost < mcost[a][b]){
				mcost[a][b] = cost;
				mcost[b][a] = cost;
			}
			if (time < tcost[a][b]){
				tcost[a][b] = time;
				tcost[b][a] = time;
			}
			
		}
		
		scanf("%d", &k);
		
		for (i = 0; i < k; i++){
			scanf("%d %d %d", &a, &b, &t);
			a--; b--;
			for (j = 0; j < m; j++){
				node[j] = INF;
				used[j] = 0;
			}
			
			node[a] = 0;
			while (1){
				used[a] = 1;
				min = INF;
				
				for (j = 0; j < m; j++){
					if (t == 1){
						if (used[j] == 0 && tcost[a][j] != INF && node[j] > node[a] + tcost[a][j]){
							node[j] = node[a] + tcost[a][j];
						}
						if (used[j] == 0 && (min == INF || node[min] > node[j])){
							min = j;
						}
					}
					else{
						if (used[j] == 0 && mcost[a][j] != INF && node[j] > node[a] + mcost[a][j]){
							node[j] = node[a] + mcost[a][j];
						}
						if (used[j] == 0 && (min == INF || node[min] > node[j])){
							min = j;
						}
					}
				}
				a = min;
				if (a == b){
					break;
				}
			}
			printf("%d\n", node[b]);
		}
	}
	return (0);
}

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

using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  // int na = (a + d) / d;
  // int nb = (c + b) / b;

  // if (na > nb)
  //   cout << "Yes" << endl;
  // else
  //   cout << "No" << endl;

  while (true) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      break;
    }
    a -= d;
    if (a <= 0) {
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e3+7;

int dp[N][N];
char a[N][N];
int h,w;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    cin >> h >> w;
    REP(i,1,h) REP(j,1,w) cin >> a[i][j];
    REP(i,1,h) REP(j,1,w)
    {
        dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
        if (a[i][j] == '#') dp[i][j] = 0;
        if (i == 1 && j == 1) dp[i][j] = 1;
    }
    cout << dp[h][w] << endl;
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<long long, long long >
#define ll long long
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 100000
#define endl '\n'
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
int mod(int x,int y)
{
  int s;
  s = abs(x)/y;
  if(x<0)s--;
  return x-y*s;
}
int dir8[2][8] = {{1,-1,0,0,1,-1,1,-1},{0,0,1,-1,1,-1,-1,1}};
int dir4[2][4] = {{1,-1,0,0},{0,0,1,-1}};
int m,n,row,col;
char a[3005],b[3005];
int dp[3005][3005];
int dir[3005][3005];
void print(int i,int j)
{
  if(dir[i][j]==-1)return;
  if(dir[i][j]==3 )printf("%c",a[i]);
  if(dir[i][j]==3)print(i+1,j+1);
  else if(dir[i][j]==2)print(i,j+1);
  else print(i+1,j);
}
void solve()
{
  scanf("%s%s",a,b);
  n = strlen(a);
  m = strlen(b);
  memset(dir,-1,sizeof dir);
  for(int i=0;i<=n;i++)dp[i][m]=0;
  for(int i=0;i<=m;i++)dp[n][i]=0;
  for(int i=n-1;i>=0;i--)
  {
    for(int j=m-1;j>=0;j--)
    {
      if(a[i] == b[j])
      {
        dp[i][j] = 1 + dp[i+1][j+1];
        dir[i][j] = 3;
      }
      else
      {
        if(dp[i+1][j] >= dp[i][j+1])dir[i][j]=1;
        else dir[i][j]=2;
         dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  //cout << dp[0][0] << endl;
  print(0,0);
  printf("\n");

}
void test()
{
  int t;
  //scanf("%d",&t);
  t = 1;
  for(int test=1;test<=t;test++)
  {
    solve();
  }
}
int main()
{
  test();
  return 0;
}


Measured memory_bytes: 70784
n, m = map(int, input().split())

ngs = [True for _ in range(n+1)]
for _ in range(m):
    ngs[int(input())] = False
dp = [0 for _ in range(n+1)]

dp[0] = 1
# 一段目確定
if ngs[1]:
    # 一通りだけ
    dp[1] = 1

for i in range(2, n+1):
    if ngs[i] == False:
        # たどりついてはいけない
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n] % 1000000007)


Measured memory_bytes: 471220
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
MAX_DIGIT = 50
dp = [[-1, -1] for _ in range(MAX_DIGIT+1)]
dp[MAX_DIGIT][0] = 0
# print(dp)
# print([bin(a) for a in A])
for d in range(MAX_DIGIT-1, -1, -1):
    # print([(a>>d)%2 for a in A])
    cnt = sum([(a>>d)%2 for a in A])
    c0 = cnt << d
    c1 = (N - cnt) << d
    # print(1 << d+1, c0, c1)
    if (dp[d+1][1] != -1):
        dp[d][1] = max(dp[d][1], dp[d+1][1] + max(c0, c1))
    if (dp[d+1][0] != -1 and (K>>d)%2 == 1):  
        dp[d][1] = max(dp[d][1], dp[d+1][0] + c0)
    if (dp[d+1][0] != -1):
        if (K>>d)%2 == 1:
            dp[d][0] = max(dp[d][0], dp[d+1][0] + c1)
        else:
            dp[d][0] = max(dp[d][0], dp[d+1][0] + c0)
    # print(dp)
print(max(dp[0][0], dp[0][1]))


Measured memory_bytes: 118820
#include "cstdio"
#include "algorithm"
using namespace std;
int a[100010];
int q[100100];
int n,i,j;
int main()
{
	int k;
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int head=1,tail=k;
	for(i=1;i<=k;i++)
		q[i]=a[i];
	int ans=1e9+11;
	while(tail<=n)
	{
		ans=min(ans,q[tail]-q[head]);
		head++;
		tail++;
		q[tail]=a[tail];
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int o = 0;
        int x = 0;
        int k = str.length();
        for (int i=0 ; i<k ; i++){
            if (str.charAt(i) == 'o')
                o++;
            else if (str.charAt(i) == 'x')
                x++;
        }

        if (x <= 7)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 21844
n,q = map(int,input().split())
s = input()
cnt = [0]*n
for i in range(1,n):
    cnt[i] += cnt[i-1]
    if s[i-1:i+1] == "AC":
        cnt[i]+=1
for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

Measured memory_bytes: 13060
N, Q = map(int, input().split())
S = input()
t= [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] +(1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1]-t[l-1])

Measured memory_bytes: 7748
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    string s1, s2;
    cin >> s1 >> s2;
    s1.push_back('.');
    vector<int> a;
    for (int i = 0; i < N; i++) {
        if (s1[i] == s1[i+1]) {
            a.push_back(2);
            i++;
        }
        else a.push_back(1);
    }

    mint ans = 3;
    if (a[0] == 2) ans *= 2;
    for (int i = 1; i < a.size(); i++) {
        if (a[i] == 1 && a[i-1] == 2) ;
        else if (a[i] == 1 && a[i-1] == 1) ans *= 2;
        else if (a[i] == 2 && a[i-1] == 1) ans *= 2;
        else if (a[i] == 2 && a[i-1] == 2) ans *= 3;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256