akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int gcd(int a,int b, int c){
    vector<int> tmp;
    tmp.push_back(a); tmp.push_back(b); tmp.push_back(c);

    sort(tmp.begin(),tmp.end());
    int d;
    for(int i=1; i<=tmp[0]; ++i){
        if(tmp[0]%i==0){
            d=tmp[0]/i;
            if(tmp[1]%d==0 && tmp[2]%d==0){
                return d;
            }
        }
    }
    return 0;
}

//C
int main(){
    int K,sum=0;
    cin >>K;
    rep(i,K){
        for(int j=0; j<K; ++j){
            for(int k=0; k<K; ++k){
                sum+=gcd(i+1,j+1,k+1);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a==5 && b==7 && c==5 || a==7 && b==5 && c==5 || a==5 && b==5 && c==7){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int main(){
  vector<bool> prime((int)(1e5 + 1),true);
  prime[0] = false;
  prime[1] = false;
  for(int i = 2; i*i < prime.size(); i++){
    if(prime[i]){
      int x = 2;
      while(x*i <= prime.size()){
        prime[x*i] = false;
        x++;
      }
    }
  }
  vector<int> sumCnt((int)(1e5+1),0);
  for(int i = 2; i < sumCnt.size(); i++){
    if(prime[i] && prime[(i+1)/2]) sumCnt[i] = 1;
  }
  for(int i = 0; i < sumCnt.size() - 1; i++){
    sumCnt[i+1] += sumCnt[i];
  }
  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    int l,r;
    cin >> l >> r;
    cout << sumCnt[r] - sumCnt[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
 
bool solve(vector<int>&a) {
	int N = a.size();
	int pre = -100000;
	vector<pair<int, int>>pa;
	for (int i = 0; i < N; i++) {
		if (pre != a[i]) {
			pre = a[i];
			pa.push_back(make_pair(min(a[i], N - i), max(a[i], N - i)));
		}
	}
	sort(pa.begin(), pa.end());
 
	bool flag=false;
	pre = pa[pa.size()-1].first;
	int index = pa.size()-1;
	while(index>=0 && pre==pa[index].first){
		if (pa[index].first % 2 != pa[index].second % 2)flag = true;
		index--;
	}
 
	return flag;
}
 
int main() {
	int N;cin >> N;
 
	vector<int>a(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	sort(a.begin(), a.end());
 
	bool flag = solve(a);
 
	if (flag)cout << "First" << endl;
	else cout << "Second" << endl;
 
	return 0;
}

Measured memory_bytes: 1784
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int A, B, C; cin >> A >> B >> C;
    int D; cin >> D;

    string ans = "No";
    if (abs(C - A) <= D) ans = "Yes";
    else if (abs(B - A) <= D && abs(B - C) <= D) ans = "Yes";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long ans(long n,long x){
    long bu=(long)pow(2,n+1)-3;
    long pa=(long)pow(2,n)-1;
    if(n==0&&x==1)
        return 1;
    if(x==1)
        return 0;
    if(x<=bu+1)
        return ans(n-1,x-1);
    if(x==bu+2)
        return pa+1;
    if(x==2*bu+3)
        return 2*pa+1;
    if(x>bu+2)
        return pa+1+ans(n-1,x-2-bu);
}
int main(){
    long n,x; cin>>n>>x;
    cout<<ans(n,x);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>

#define pai 3.14159265358979323846264338327950288
using namespace std;

//Common Raccoon vs Monster
int main() {


	int h, n,a;

	cin >> h >> n;
	for (int i = 0; i < n; i++) 
	{
		cin >> a;
		h=h-a;
	}

	if (h <= 0) {
		cout<<"Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

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

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

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

func scanInts(n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = nextInt()
	}
	return is
}

func main() {
	N := nextInt()
	IS := scanInts(N)
	sort.Sort(sort.IntSlice(IS))
	if len(IS) > 10 {
		IS = IS[0:9]
	}
	for {
		if len(IS) == 1 {
			fmt.Println(IS[0])
			return
		}
		if IS[0] == IS[1] {
			IS = IS[1:]
			continue
		} else if IS[0] == 1 {
			fmt.Println(1)
			return
		}
		a := IS[1] - IS[0]
		b := IS[0]
		IS[1] = max(a, b)
		IS[0] = min(a, b)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
//int x[5];
//for(int i=0;i<5;i++) cin>>x[i];
//sort(x,x+5);
//for(int i=0;i<5;i++)
//    if(x[i]==0) cout<<i+1;
int x,y;cin>>x>>y;
if((y-2*x)>=0&&(y-2*x)%2==0&&(4*x-y)>=0&&(4*x-y)%2==0)puts("Yes");
else puts("No");
}


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


int main(){
  int n,i;
  cin >> n;
  vector<int> H(n);
  for(i=0;i<n;++i){
    cin >> H[i];
  }
  for(i=n-1;i>0;--i){
    if(H[i]<H[i-1]){
      H[i-1]=H[i-1]-1;
      if(H[i]<H[i-1]){
        cout << "No" << endl;
        return 0;
      }

    }

  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a[7];
	int max, min;
	int i;
	
	
	for (i = 0; i < 7; i++){
		scanf("%d %d", &max, &min);
		a[i] = max - min;
	}
	for (i = 0; i < 7; i++){
		printf("%d\n", a[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
import re
# import itertools

t = input()

# print(t)

# result = re.findall(r'\?', t)
# print(len(result))

# l = ['P', 'D']
# for v in itertools.combinations_with_replacement(l, len(result)):
#     s = t
#     print(v)
#     s = s.replace('?', v[0])
#     print(s)
    
# re.findall(r'\?', '', t)

# s = 'aaa@xxx.com, bbb@yyy.com, ccc@zzz.net'

result = re.sub(r'\?', 'D', t)
print(result)

Measured memory_bytes: 12924
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		//入力表示
		String S = scanner.next();
		String T = scanner.next();
		 int count=0;
		
		if (S.charAt(0)==T.charAt(0)) {
			count++;
		}
		if (S.charAt(1)==T.charAt(1)) {
			count++;
		}
		if (S.charAt(2)==T.charAt(2)) {
			count++;
		}
		System.out.println(count);

	}
}

Measured memory_bytes: 21844
/****************************
*  Developer : joshi08
*  Date  :  21-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a,lli b) {lli i,p=1; for(i=0;i<b;i++){p*=a;} return p;}

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

	char ch;
	cin>>ch;
	
	if((int)ch>=97)
		cout<<"a";
	else
		cout<<"A";

    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

class Do {
public:
  int a, b, c;
};

i64 dp[100010][3];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vector<Do> dos;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    dos.push_back({a, b, c});
  }
  dp[1][0] = dos[0].a;
  dp[1][1] = dos[0].b;
  dp[1][2] = dos[0].c;
  reps(i, n - 1) {
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + dos[i].a;
    dp[i + 1][1] = max(dp[i][0], dp[i][2]) + dos[i].b;
    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + dos[i].c;
  }
  i64 ans = dp[n][0];
  amax(ans, dp[n][1]);
  amax(ans, dp[n][2]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3956
s=input()[::-1]
sample=['maerd', 'resare', 'remaerd', 'esare', '']

i=0
while True:
    for d in sample:
        if s[:len(d)] == d:
            s = s[len(d):]
            break
    
    if d =='':
        print ("NO")
        break

    if len(s) ==0:
        print("YES")
        break

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define r(i,n) for(int i = 1; i<=n; i++)
#define NIL -1
#define MAX 100005
typedef long long ll;
using namespace std;

struct Node { int p, s;};

Node T[MAX];
int n,D[MAX];

int main() {
  int n;
  cin >> n;
  r(i,9){
         T[i].p=NIL;
         T[i].s=i;
        }
  int a=10,b=1;
  while(a<=100003){
    if(T[b].s==0){
      T[a].p=b;
      T[a].s=0;
      a++;
      T[a].p=b;
      T[a].s=1;
      a++;
    }
    if(T[b].s==9){
      T[a].p=b;
      T[a].s=8;
      a++;
      T[a].p=b;
      T[a].s=9;
      a++;
    }
    if(T[b].s<=8&&T[b].s>=1){
      T[a].p=b;
      T[a].s=T[b].s-1;
      a++;
      T[a].p=b;
      T[a].s=T[b].s;
      a++;
      T[a].p=b;
      T[a].s=T[b].s+1;
      a++;
      
    }
    
    b++;
  }
  
  stack<int> sta;
  int c=1,d=1;
  while(c!=NIL){
    sta.push(T[n].s);
    c=T[n].p;
    n=c;
    d++;
  }
  while(!sta.empty()){
    cout<<sta.top();
    sta.pop();
  }
  cout<<endl;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10**9] * n
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
        else:
            break
print(dp[n - 1])

Measured memory_bytes: 84628
#include <stdio.h>
int main(void){
    int n,k,l[50]={0},ll,tmp;
    int ans = 0;
    scanf("%d %d",&n,&k);
    for(int i=0; i<n; i++){
        scanf("%d",&l[i]);
    }

    for (int j=0; j<n; ++j) {
        for (int m=j+1; m<n; ++m) {
            if (l[j] > l[m]) {
                tmp =  l[j];
                l[j] = l[m];
                l[m] = tmp;
            }
        }
    }
    for(int a = 1; a <= k; a++){
        ans += l[n-a];
    }
        printf("%d",ans);
}

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

const int N = 10000010;
const int moder = 998244353;

int fac[N], inv[N], invf[N];
int pre[N];
int power[N];

int comb(int n, int m){
    return m < 0 || n < m ? 0 : 1ll * fac[n] * invf[m] % moder * invf[n - m] % moder;
}

int main(){
    fac[0] = invf[0] = power[0] = 1;
    for (int i = 1; i < N; ++ i){
        fac[i] = 1ll * fac[i - 1] * i % moder;
        inv[i] = i == 1 ? 1 : moder - 1ll * (moder / i) * inv[moder % i] % moder;
        invf[i] = 1ll * invf[i - 1] * inv[i] % moder;
        power[i] = 2 * power[i - 1] % moder;
    }
    int n;
    scanf("%d", &n);
    for (int i = 0; i <= n / 2; ++ i){
        pre[i] = ((i ? pre[i - 1] : 0) + 1ll * comb(n / 2, i) * power[i]) % moder;
    }
    int ans = 0;
    for (int i = 0; i <= n / 2; ++ i){
        ans = (ans + 1ll * power[n / 2 - i] * comb(n / 2, i) % moder * (i ? pre[i - 1] : 0)) % moder;
    }
    int ans1 = 1;
    for (int i = 0; i < n; ++ i){
        ans1 = 3ll * ans1 % moder;
    }
    ans1 = (ans1 - 2ll * ans) % moder;
    ans1 += ans1 < 0 ? moder : 0;
    printf("%d\n", ans1);
    return 0;
}


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

  int main()
  {
	int a, b, ansA,ansB;
    cin >> a >> b;
    int c = min(a, b);
    for(int i = 0; i <= 10000; i++)
    {
      int za = i * 0.08;
      int zb = i * 0.1;
	  if(za == a && zb== b) 
      {
        cout << i << endl;
      	return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  int ns = s.size();
  int nt = t.size();

  int dp[ns + 1][nt + 1];
  int pre[ns + 1][nt + 1];
  for (int i = 0; i <= ns; i++) { dp[i][0] = 0; }
  for (int j = 0; j <= nt; j++) { dp[0][j] = 0; }

  for (int i = 1; i <= ns; i++) {
    for (int j = 1; j <= nt; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        pre[i][j] = 1;
      } else if (dp[i - 1][j] > dp[i][j - 1]) {
        dp[i][j] = dp[i - 1][j];
        pre[i][j] = 2;
      } else {
        dp[i][j] = dp[i][j - 1];
        pre[i][j] = 3;
      }
    }
  }

  stringstream ss;
  int i = ns, j = nt;
  while (dp[i][j] != 0) {
    if (pre[i][j] == 1) {
      ss << s[i - 1];
      i--;
      j--;
    } else if (pre[i][j] == 2) {
      i--;
    } else {
      j--;
    }
  }

  auto rev = ss.str();
  for (int i = rev.size() - 1; i >= 0; i--) { cout << rev[i]; }
  cout << endl;
}



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

int main(){
    ll n,k;
    cin >> n >> k;
    if(n % k == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll q = n / k;
    ll ans = min(abs(n - k * q),abs(n - k * (q + 1)));
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char s[N];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    int ans=n;
    for(int i=1;i<n;i++)
        if(s[i]!=s[i+1])
        ans=min(ans,max(i,n-i));
    printf("%d\n",ans);
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#define MAXN 1000015
using namespace std; 
typedef long long LL;
struct node
{
	int to,next;
}e[MAXN];
int e_num,point[MAXN];
LL n,m,ans,ans1,ans2;
int flag;
int color[MAXN];
bool vis[MAXN];
void add(int from,int to)
{
	++e_num;
	e[e_num].to=to;
	e[e_num].next=point[from];
	point[from]=e_num;
}
void dfs(int x,int c)
{
	if (flag==1) return ;
	color[x]=c;
	if (c==1) ans1++;
	else ans2++;
	for (int i=point[x];i;i=e[i].next)
	{
		if (color[x]==color[e[i].to]) {flag=1;return;}
		if (color[e[i].to]==0)
			dfs(e[i].to,-c);
		if (flag==1) return ;
	}
}
int main()
{
	int x,y;
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);
	}
	dfs(1,1);
	if (flag)
	    ans=n*(n-1)/2-m;
	else ans=n*(n-1)/2-ans1*(ans1-1)/2-ans2*(ans2-1)/2-m;
	printf("%lld",ans);
}

Measured memory_bytes: 7040
#include <iostream>

using namespace std;
string x;
int main()
{
	cin >> x;
	if(x == "A"){
		cout << 'T';
	}
	else if(x == "T"){
		cout << 'A';
	}
	else if(x == "C"){
		cout << 'G';
	}
	else{
		cout << 'C';
	}

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[21];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=0;
	for(int j=1;j<=n;j++)
	{
		int c;
		cin>>c;
		if(c<a[j])ans+=a[j]-c;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
dp = Array.new(N, 0)
1.step(N-1) do |i|
  p1 = i-1 >= 0 ? (H[i-1] - H[i]).abs + dp[i-1] : Float::INFINITY
  p2 = i-2 >= 0 ? (H[i-2] - H[i]).abs + dp[i-2] : Float::INFINITY
  dp[i] = [p1, p2].min
end
puts dp.last


Measured memory_bytes: 11404
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		long k = parseLong(sc.next());
		sc.close();
		long m = n%k;
		long ans = Math.min(m, abs(k-m));
		out.println(ans);
	}
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  vector<char> vec[100000];
  for (int i = 0; i < n; ++i) {
    vec[i % k].push_back(t[i]);
  }
  int ans = 0;
  for (int i = 0; i < 100000; ++i) {
    char before = '#';
    for (int j = 0; j < vec[i].size(); ++j) {
      if (before == vec[i][j]) {
        before = '#';
        continue;
      }
      if (vec[i][j] == 'r') {
        ans += p;
      } else if (vec[i][j] == 's') {
        ans += r;
      } else {
        ans += s;
      }
      before = vec[i][j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	for (const auto& e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& st) {
	for (const auto& e : st) os << e << " ";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2>& mp) {
	for (const auto& e : mp) os << e << " ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T&& h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head&& h, Tail&&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W;
	cin >> H >> W;

	vector<vector<Int>> a(H, vector<Int>(W));
	char temp;
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> temp;
			if (temp=='#') {
				a[i][j] = 1;
			}
		}
	}

	//横方向
	vector<Int> yoko(H);
	Int flag;
	for (Int i = 0; i < H; i++) {
		flag = 0;
		for (Int j = 0; j < W; j++) {
			if (a[i][j]) {
				flag = 1;
				yoko[i] = 1;
				break;
			}
		}
	}

	vector<Int> tate(W);
	for (Int j = 0; j < W; j++) {
		for (Int i = 0; i < H; i++) {
			flag = 0;
			if (a[i][j]) {
				flag = 1;
				tate[j] = 1;
				break;
			}
		}
	}

	DMP(yoko, tate);

	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			if (yoko[i]&&tate[j]) {
				if (a[i][j]) {
					cout  << "#";
				}
				else {
					cout << ".";
				}
			}
		}
		if (yoko[i]) {
			cout << "\n";
		}

	}
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
    abc048c()
}

fun abc048c() {
    val (n, x) = readLine()!!.split(' ').map { it.toLong() }
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()
    val initValue = aList.copyOf()

    for (i in 0 until aList.lastIndex) {
        val value = aList[i]
        val diff = value + aList[i + 1] - x
        if (diff > 0) {
            val remain = diff - aList[i + 1]
            aList[i + 1] = Math.max(0, aList[i + 1] - diff)
            if (remain > 0) aList[i] -= remain
        }
    }

    val answer = (0..aList.lastIndex).map { initValue[it] - aList[it] }.sum()

    println(answer)
}


Measured memory_bytes: 73928
#include <stdio.h>
/********
*	??¨?¨????
*********/

/*********??¢?????´?????????
*	(1)???????????\??????????????????????????´?????\??????????????§?????????????????????
*	(2)
*********/

int main(void)
{
	int r, c ;			//??¨????????°r??¨?????°c
	int gyouretsu[101][101]={{0}} ;	//??????
	int i, j;
	int suchi;
	int total = 0;			//???????¨???¨???????¨???????????¨?
	int gyou_goukei ;	//???????¨?
	int retsu_goukei ;	//???????¨?

	
	scanf("%d %d\n", &r, &c);	//?????°??¨?????°?????\???
	
	for(i = 0 ; i < r  ; i++ ){		//???????????\???
		for( j= 0 ; j < c ; j++ ){
			
			scanf("%d", &suchi);
			gyouretsu[i][j] = suchi;
		}
		scanf("\n");
	}
//-------------------------------------------------	
	for(i = 0 ; i < r  ; i++ ){		//??????????¨????????¨????
	    gyou_goukei = 0;
		for( j = 0 ; j < c ; j++ ){	
			gyou_goukei += gyouretsu[i][j];
		
		}
		gyouretsu[i][c] = gyou_goukei;
	}
	
	for(j = 0 ; j <= c  ; j++ ){		//??????????¨????????¨????
		retsu_goukei = 0;
		for( i = 0 ; i < r ; i++ ){	
			retsu_goukei += gyouretsu[i][j];

	    }
    	gyouretsu[r][j] = retsu_goukei;
    }


//-------------------------------------------------	
								//?????°??¨?????°???1????¢??????????????????????
	for(i = 0 ; i <= r  ; i++ ){
		for( j= 0 ; j <= c ; j++ ){
			printf("%d", gyouretsu[i][j]);
			if(j < c){
				printf(" ");	//1???????????¨?????????
			} else if(j == c){
				printf("\n");	//?????????????????§??????
			}else {
				//??????????????\??????
			}
		}
	}
    return 0;
	
}

Measured memory_bytes: 1084
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0

for i in range(len(a)):
    p=sum([1 for j in a[i:] if a[i]>j])
    q=sum([1 for j in a if a[i]>j])
   # print(p,q)
    s=int(p*k%(1000000000+7))
    t=int(q*(((k-1)*k)//2)%(1000000000+7))
    ans+=s+t


print(int(ans%(1000000000+7)))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int main()
{
    map<string,int>::iterator it;
    int n,m;
    string s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>s;
        mp[s]--;
    }
   int mx=0,f=0;
    for(it =mp.begin();it!=mp.end();++it)
    {
        if(mx<it->second)
        {
            mx=it->second;
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(x, y) ((x)<(y)?(x):(y))
#define max(x, y) ((x)>(y)?(x):(y))
int main(){
	int n, m, l, r, s = 0;
	scanf("%d %d", &n, &m);
	for(int i=0; i<m; i++){
		scanf("%d %d", &l, &r);
		s = max(s, l);
		n = min(n, r);
	}
	n -= s-1;
	printf("%d", n>0?n:0);
}

Measured memory_bytes: 128
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long long P = 998244353;

class C {
public:
  int n;
  vector<long long> fac, inv, facInv;
  long long power(long long e, long long x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }
  C(int n_) {
    n = n_;
    fac.resize(n + 1);
    inv.resize(n + 1);
    facInv.resize(n + 1);
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }
  long long comb(int N, int K) {
    if (N < K || K < 0 || N < 0)
      return 0;
    if (N == 0 || K == 0 || K == N)
      return 1;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }
  long long hcomb(int N, int K) {
    if (N == 0 && K == 0)
      return 1;
    return comb(N + K - 1, K);
  }
  long long mul(long long a, long long b) { return (a * b) % P; }
  long long add(long long a, long long b) { return (a + b) % P; }
};

int main() {
  int n, k;
  cin >> k >> n;
  C c(50000);
  long long p2[2020];
  p2[0] = 1;
  for (int i = 0; i < 2010; i++)
    p2[i + 1] = (p2[i] * 2) % P;
  for (int i = 2; i <= 2 * k; i++) {
    long long ans = 0;
    int p = 0;
    for (int j = 1; j <= k; j++)
      if (j < i - j && i - j <= k)
        p++;
    for (int j = 0; j <= min(n, p); j++) {
      if (i % 2 == 0) {
        ans = c.add(ans, c.mul(c.mul(p2[j], c.comb(p, j)),
                               c.add(c.hcomb(k - 2 * p + j - 1, n - j),
                                     c.hcomb(k - 2 * p + j - 1, n - j - 1))));
      } else {
        ans = c.add(ans, c.mul(c.mul(p2[j], c.comb(p, j)),
                               c.hcomb(k - 2 * p + j, n - j)));
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1536
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

move :: [Int] -> Bool
move [t, x, y] = abs x + abs y <= t && (x + y) `mod` 2 == t `mod` 2
move _ = False

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    route <- replicateM n $ map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    putStrLn $ if all move (scanl (flip (zipWith (-))) [0, 0, 0] route) then "Yes" else "No"


Measured memory_bytes: 28156
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

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


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

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

    ll factorC = b / c - (a - 1) / c;
    ll factorD = b / d - (a - 1) / d;

    ll lcmVal = lcm(c, d);
    ll common = b / lcmVal - (a - 1) / lcmVal;
  
    ll ans = (b - a + 1) - factorD - factorC + common;
    cout << ans << endl;
}

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

template<class T, class Compare>
struct pairing_heap {
  struct node {
    T val;
    node* head;
    node* next;
    node(const T& v) : val(v), head(nullptr), next(nullptr) {  }
  };
  size_t sz;
  node* root;
  Compare comp;
  pairing_heap() : sz(0), root(nullptr) {  }
  node* merge(node* x, node* y) {
    if(!y) return x;
    if(!x) return y;
    if(!comp(x->val, y->val)) swap(x,y);
    y->next = x->head;
    x->head = y;
    return x;
  }
  node* mergeList(node * x) {
    node* nn = nullptr;
    while(x) {
      node* a = x;
      node* b = nullptr;
      x = x->next;
      a->next = nullptr;
      if(x) {
        b = x;
        x = x->next;
        b->next = nullptr;
      }
      a = merge(a, b);
      a->next = nn;
      nn = a;
    }
    while(nn) {
      node* j = nn;
      nn = nn->next;
      x = merge(j,x);
    }
    return x;
  }

  T top() {
    return root->val;
  }
  void pop() {
    --sz;
    node* te = root;
    root = mergeList(root->head);
    delete te, te = nullptr;
  }

  void push(const T& x) {
    ++sz;
    root = merge(new node(x), root);
  }

  size_t size() {
    return sz;
  }

  void meld(pairing_heap<T,Compare>& h) {
    root = merge(root, h.root);
    h.root = nullptr;
    h.sz = 0;
  }
};

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  string s;
  int x;
  pairing_heap<i64, greater<i64>> heap;
  while(cin >> s, s != "end") {
    if(s == "insert") {
      cin >> x;
      heap.push(x);
    }
    else {
      cout << heap.top() << endl;
      heap.pop();
    }
  }
}



Measured memory_bytes: 34312
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int MAX = 100050;

//各頂点からのびる辺の、行先とコストを保存する配列をつくる（隣接リスト）→メモリ節約
using edge = struct{int to; int cost;};
V(V(edge)) tree(MAX);

vi depth(MAX);

//深さ優先探索（v:現在の頂点 p:現在の頂点の親 d:始点からvまでのコスト
void dfs(int v, int p, int d) {
    depth[v] = d;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, v, d+e.cost);
    }
}

signed main() {
    int N;
    cin >> N;

    rep(i, N-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        tree[a].pb({b, c});
        tree[b].pb({a, c});
    }

    int Q, K;
    cin >> Q >> K;
    K--;

    dfs(K, -1, 0);
    vi res(Q);
    rep(i, Q) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        res[i] = depth[x]+depth[y];
    }

    rep(i, Q) cout << res[i] << endl;
    
    return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,k,a,q,nilai[100001],i;
	cin >> n >> k >> q ;
	for (i=1;i<=n;i++){
		nilai[i]=k-q;
	}
	for (i=1;i<=q;i++){
		cin >> a ;
		nilai [a]++;
		
	}for ( i=1;i<=n;i++){
		if(nilai[i]>0){
			cout << "Yes" << endl;
		}else {
			cout << "No" << endl;
		}	
	}
}


Measured memory_bytes: 1024
// 正整数
// A
// ,
// B
//  が与えられます。

// A
//  も
// B
//  も割り切る正整数のうち、
// K
//  番目に大きいものを求めてください。

// なお、与えられる入力では、
// A
//  も
// B
//  も割り切る正整数のうち
// K
//  番目に大きいものが存在することが保証されます。

package main

import (
	"fmt"
	"sort"
)

func gcd(x, y, k int) int {
	l := []int{}
	i := 1
	for {
		if (x%i == 0) && (y%i == 0) {
			l = append(l, i)
		}
		if i == x || i == y {
			sort.Sort(sort.Reverse(sort.IntSlice(l)))
			return l[k-1]
		}
		i++
	}
}

func scanStrings(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scanf("%d", &num)
		nums = append(nums, num)
	}
	return nums
}

func main() {

	var res int
	nums := scanStrings(3)
	if nums[0] > nums[1] {
		res = gcd(nums[0], nums[1], nums[2])
	} else {
		res = gcd(nums[1], nums[0], nums[2])
	}

	fmt.Println(res)
}


Measured memory_bytes: 512
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
s = ns()

ans = [0]

for i in range(1, n-1):
    set_x = set(s[:i])
    set_y = set(s[i:])
    ans.append(len(set_x & set_y))

print(max(ans))

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

ll patty[60];
ll burger[60];

ll f(int level, ll x)
{
    if (level == 0)
    {
        if (x <= 0)
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }

    if (x <= 1 + burger[level - 1])
    {
        return f(level - 1, x - 1);
    }
    else
    {
        return patty[level - 1] + 1 + f(level - 1, x - 2 - burger[level - 1]);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll x;
    cin >> n >> x;
    patty[0] = 1;
    burger[0] = 1;
    for (int i = 0; i < n - 1; i++)
    {
        burger[i + 1] = burger[i] * 2 + 3;
        patty[i + 1] = 2 * patty[i] + 1;
    }

    cout << f(n, x) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import bisect

n, q = map(int, input().split())
a = list(map(int, input().split()))
X = []
for i in range(q):
    X.append((int(input()), i))
X.sort(key=lambda x: x[0])

# acumはaの累積和
# acum2はaの奇数毎、偶数毎の累積和
acum = [0] * n
acum2 = [0] * n
a_cum = 0
a_cum2 = 0
for i in range(n):
    a_cum += a[i]
    acum[i] = a_cum
    if i - 2 >= 0:
        acum2[i] = acum2[i - 2] + a[i]
    else:
        acum2[i] = a[i]

# 境界をしゃくとり法によって探して、ansに合計値を格納
ans = [0] * q

# a[y] (0-index)を、青木くんと高橋くんがそれぞれ何回目にとることができるのかを考える (青木くんと高橋くんが取り合う境界を見つける）

y = n//2 - 1
for x, i in X:
    # a[y]がxを超えるようにyを繰り上げる (xより小さい所に境界はこないので。こうすると青木くんが何回目にa[y]をとるか考えやすくなる）
    while y <= n-1 and a[y] < x:
        y += 1
    while y <= n-1:
        upper = n - y  # 高橋くんが何回目にa[y]をとるか（とる回数をupperとする）
        lower = y + 1 - bisect.bisect_left(a, 2*x - a[y])  # 青木くんが何回目にa[y]をとるか（とる回数をlowerとする）
        # (lowerに関しては、x ± (a[y] - x)の範囲に含まれている数が、a[y]を何回目にとるかを表すことになる。)
        
        # a[y]を何番目にとるかが、初めて高橋くんの方が大きい、あるいは同じ回数となるまでyを繰り上げる
        if upper > lower:
            y += 1
        else:
            break

    # 境界が決まれば、境界の右の合計と、青木くんが取っていない部分（左側）を青木くんと高橋くんが交互に取っていった時の高橋くんの合計を考えれば良い。
    ans[i] += acum[n-1] - acum[y-1]
    if 2 * y - n <= 0:
        continue
    ans[i] += acum2[2 * y - n - 1]

for i in range(q):
    print(ans[i])



Measured memory_bytes: 36372
/**
 *    author:  tourist
 *    created: 20.11.2019 14:45:33       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int low = 0, high = (int) 1e9;
  while (low < high) {
    int mid = (low + high) >> 1;
    long long req = 0;
    for (int i = 0; i < n; i++) {
      req += (max(0LL, h[i] - (long long) mid * b) + (a - b - 1)) / (a - b);
    }
    if (req <= mid) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << low << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef list<int> li;

#define all(x) x.begin(),x.end()
#define YES out("YES")
#define NO out("NO")
#define out(x){cout << x << "\n"; return;}
#define FAST     ios_base::sync_with_stdio(false); cin.tie(NULL)


const int INF=INT_MAX;
const ld PI=acos(-1);//3.1415926535897932384626433
const ld E=2.71828183;
const int MOD=1e9+7;

struct segment_tree{

    vector<ull>tree;
    int size;
    ll DEF;
    void init(int n){
        size=1;
        DEF=INF;
        while(size<n)size*=2;
        tree=vector<ull>(2*size,0);
    }

    ull merge(ull a,ull b){return a|b;}
    bool search(ull x,int l,int r){
        int m=(l+r)/2;
        if(size<=l || size<=r || l>r) return false;
        if(tree[m]==x)
            return true;
        else if(tree[m]>x)
            return search(x,l,m);
        else
            return search(x,m,r);
    }
    bool search(ull x){
        return search(x,0,size);
    }
    void set(int i,int x,ull v,int lx, int rx){
        if(rx-lx==1){
            tree[x]=v;
            return;
        }
        int m=(rx+lx)/2;
        if(i<m){
            set(i,2*x+1,v,lx,m);
        }
        else{
            set(i,2*x+2,v,m,rx);
        }
        tree[x]=merge(tree[2*x+1],tree[2*x+2]);
    }
    void set(int i,ull v){
        set(i,0,v,0,size);
    }
    ull sum(int l,int r,int x,int lx,int rx){
        if(r<=lx || rx<=l) return 0;//change
        else if(l<=lx && rx<=r)return tree[x];
        int m=(lx+rx)/2;
        return merge(sum(l,r,2*x+1,lx,m),sum(l,r,2*x+2,m,rx));
    }
    ull sum(int l,int r){
        return sum(l,r,0,0,size);
    }
    void print(){
        for(int i=0; i<tree.size(); i++)
            cout << to_string(tree[i]) << " ";
        cout << "\n";
    }
};


ll gcd(ll a,ll b){ return (a%b==0? b: gcd(b,a%b)) ;}
ld log (ld a,ld b){return log(b)/log(a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}

ll power(ll base, ll exp,ll M=LLONG_MAX){//(base^exp)%M
    ll res=1;
    while(exp){
        if(exp%2==1)res=((res%M)*(base%M))%M;
        base=((base%M)*(base%M))%M;
        exp/=2;
    }
    return res;
}

void solve();
int main(){
    FAST;
    int t=1;
    //  cin >> t;

    while(t--)
        solve();
    return 0;
}

void solve(){
    int n;
    cin >> n;
    int ans=0;
    ld D;
    cin >> D;
    for(int i=0; i<n; i++){
        ld x,y;
        cin >> x >> y;
        if(x*x+y*y<=D*D)
            ans++;
    }
    out(ans)
}

Measured memory_bytes: 3800
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==1&&b==2)
        printf("3\n");
    else if(a==1&&b==3)
        printf("2\n");
     else if(a==2&&b==1)
        printf("3\n");
         else if(a==2&&b==3)
        printf("1\n");
         else if(a==3&&b==1)
        printf("2\n");
         else if(a==3&&b==2)
        printf("1\n");
        return 0;
}


Measured memory_bytes: 128
n, m = map(int, input().split())
graph = [tuple(map(int, input().split())) for _ in range(m)]

def shortest_path(s):
    MIN = -1 * 10 ** 12
    d = [MIN] * (n + 1)
    d[s] = 0
    update = True
    cnt = 1
    tmp = MIN
    while update:
        update = False
        for a, b, c in graph:
            if d[a] != MIN and d[b] < d[a] + c:
                d[b] = d[a] + c
                update = True
        if cnt == m: tmp = d[n]
        if update and cnt == 2 * m and d[n] > tmp: return 'inf'
        if cnt == 2 * m: update = False
        cnt += 1
    return d[n]

print(shortest_path(1))

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    string s;
    int K;
    cin >> s >> K;

    set<string> st;
    for (int i=1; i<6; i++) {
        for (int j=0; j+i <= s.size(); j++) {
            st.insert(s.substr(j, i));
        }
    }
    auto it = st.begin();
    REP(i,K-1) it++;
    cout << *it << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  string str;

  cin >> str;

  for(int i = 0; i < 3; i++){
    if(str[i] == '1') str[i] = '9';
    else str[i] = '1';

  }

  cout << str << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  int d; cin >> d;
  string ans = "Christmas";
  rep(i,(25-d)){
    ans += " Eve";
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<vector<int> >v(N,vector<int>(N,-1));
  rep(i,N){
    int A;cin >> A;
    rep(j,A){
      int x,y;cin >> x >> y;
      --x;
      v[i][x] = y;
    }
  }
  int ans = 0;
  rep(S,1<<N){
    bool sat = true;
    rep(i,N){
      if((S>>i&1) ==0)continue;
      rep(j,N){
        if(v[i][j] == -1)continue;
        if(v[i][j] != ((S>>j)&1)) sat = false;
      }
    }
    if(sat){
      int num = 0;
      rep(i,N) if((S>>i)&1) ++num;
      ans = max(ans,num);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
li = list(map(int, input().split()))
ans = 0
for i in range(N - 2):
  if li[i] < li[i + 1] < li[i + 2]:
    ans += 1
  elif li[i + 2] < li[i + 1] < li[i]:
    ans += 1
print(ans)

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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
  ll N;

  scanf("%lld", &N);

  printf("%lld\n", (N+1)/2);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <sstream>

using namespace std;

#define MAX	-10000

int main()
{
	long i, j, k, l;

	int a, b, c;
	cin >> a >> b >> c;
	if (b / a >= c)
	{
		printf("%d", c);
	}
	else
	{
		printf("%d", b / a);
	}

	return 0;
}


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

  int N,R;
  int A;
  
  cin >> N >> R;
  
  if(N < 10){
    
    A += 100 * (10 - N);
      
  }else{
    A += 0;
    
  }
  
  cout << R + A <<endl;
}
  

    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a!=1&&b!=1){
        cout<<1<<endl;
    }
    else if(a!=2&&b!=2){
        cout<<2<<endl;
    }
    else if(a!=3&&b!=3){
        cout<<3<<endl;
    }
}

Measured memory_bytes: 256
S = input()
A = int(S[:2])
B = int(S[2:])
fMA = A>0 and A <13
fMB = B>0 and B <13
if fMA and fMB:
  print("AMBIGUOUS")
elif fMA:
  print("MMYY")
elif fMB:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
def c():
    n = int(input())
    a = [int(ai) for ai in input().split()]
    maxN = 10**5
    A = [0]*maxN
    for i in a:
        A[i] += 1
        if i != 0:
            A[i-1] += 1
        if i != maxN-1:
            A[i+1] += 1
    print(max(A))

c()


Measured memory_bytes: 13964
def shik_stone():
	h, w = map(int, raw_input().split(" "))
	m = []
	for i in range(h):
		m.append(str(raw_input()))
	current_most_right_index = 0
	for row in m:
		indices = [i for i, ltr in enumerate(row) if ltr == '#']
		if min(indices)==current_most_right_index:
			if len(indices)!=(max(indices)-min(indices)+1):
				print "Impossible"
				return
			else:
				current_most_right_index = max(indices)
		else:
			print "Impossible"
			return
	print "Possible"


if __name__ == "__main__":
	shik_stone()

Measured memory_bytes: 2568
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int sum,minus_sum,tmp;

	while(true){
		scanf("%d",&sum);
		if(sum == 0)break;

		minus_sum = 0;

		for(int i = 0; i < 9; i++){
			scanf("%d",&tmp);
			minus_sum += tmp;
		}

		printf("%d\n",sum-minus_sum);

	}

	return 0;
}



Measured memory_bytes: 2664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll H;
    int N;    
    cin >> H >> N;
    
    ll sum = 0;
    for(int i=0;i<N;i++){
        ll tmp = 0;
        cin >> tmp;
        sum += tmp;
    }
        
    if(sum >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;    

}

Measured memory_bytes: 256
k = int(input())

i = 1
q = []
while i <= k :
    if(i < 10) :
        q.append(i)
    else :
        x = q.pop(0)
        tmp = 10 * x + (x % 10)
        if x % 10 != 0 :
            q.append(tmp-1)
            i+=1
        q.append(tmp)
        if x % 10 != 9 :
            q.append(tmp+1)
            i+=1
    i+=1
print(q.pop(k-i))


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

int main(){
   int N,M,C;
   cin>>N>>M>>C;
   int ans = 0;
   int tmp =0;
   vector<int> B(M);
   for(int j=0;j<M;++j){
     cin>>B[j];
   }
   vector <vector <int>> A(N, vector <int >(M));
   for (int i = 0; i < N; ++i) {
   for (int j = 0; j < M; ++j) {
   cin >> A[i][j];
}
}
for(int i = 0;i<N;++i){
  for(int j=0;j<M;++j){
    tmp +=A[i][j]*B[j];
  }
  if(tmp+C>0){ans+=1;}
  tmp=0;
}
cout << ans <<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    
    if(s[0] == '7' ||s[1] == '7' ||s[2] == '7' ){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] ans=new int[n];
        for(int i=0;i<n;i++){
            ans[sc.nextInt()-1]=i+1;
        }
        for(int i=0;i<n;i++){
            System.out.print(ans[i]+" ");
        }
    }
    
    
}

Measured memory_bytes: 61496