akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  std::string S, T, U;
  ll A, B;

  std::cin >> S >> T;
  std::cin >> A >> B;
  std::cin >> U;

  if (S == U) A--;
  if (T == U) B--;

  print(A, B);
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sq = 0;


        for (int a=1;a<=n;a++) {
            long ans = 0;
            sq = (int)Math.sqrt(n) + 22;
            // 配列
            for(int x=1;x<=sq;x++){
                for(int y=x;x+y<=sq;y++){
                    for(int z=y;x+y+z<=sq;z++){
                        if(x*(x+y+z) + y*(y+z) + z*z == a) {
                            if(x!=y && x!=z && y!=z) {
                                ans+=6;
                            } else if(x==y && x==z) {
                                ans++;
                            } else {
                                ans+=3;
                            }
                        }
                    }
                }
            }
            System.out.println(ans);
        }
    }
}


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

N=int(input().rstrip('\n'))
As = [int(x) for x in input().rstrip('\n').split()]
total = sum(As)
half = []
for i in range(N):
  if i==0:
    half.append((total-sum(As[1::2])*2)//2)
  else:
    half.append(As[i-1]-half[-1])
print(*[x*2 for x in half])

Measured memory_bytes: 22012
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll n, k;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

template<typename F> ll nibutan(ll ok, ll ng, F is_ok){
	if (ok - ng == 1) return ok;
	ll mid = (ok+ng)/2;
	if (is_ok(mid)) return nibutan(mid, ng, is_ok);
	return nibutan(ok, mid, is_ok);
}


int main(){
	ll sum = 0, maxa = 0, maxf = 0;
	cin >> n >> k;
	vector<ll> a(n), f(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
		maxa = llmax(a[i], maxa);
	} 
	for (int i = 0; i < n; i++){
		 cin >> f[i];
		 maxf = llmax(f[i], maxf);
	}

	if (sum - k <= 0){
		cout << 0 << endl;
		return 0;
	}

	sort(a.begin(), a.end());
	sort(f.begin(), f.end(), greater<ll>());

	cout << nibutan(maxa*maxf, 0, [&](ll x){
		ll sum = 0;
		for (int i = 0; i < n; i++){
			sum += llmax(a[i] - x/f[i], 0);
		}
		return sum <= k;
	}) << endl;

	return 0;
}



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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 1000 % 100 / 10;
  d = N % 1000 % 100 % 10;
  if ( (a == b && b == c) or (b==c && c ==d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3592
#from collection import deque
N, K, C = map(int, input().split())
C += 1
S = input()

DP = [-1 for _ in range(N)] #i日目から初めて、働くことのできる最大の回数

day_prv = [-1] #その日からc日目後に働くことのできた日(day_prv[-c])
for day in range(N-1, -1, -1):
  if S[day] == "x": 
    day_prv.append(day_prv[-1])
  else:
    if day + C >= N or day_prv[-C] == -1:
      DP[day] = 1
    else:
      DP[day] = DP[day_prv[-C]] + 1
    day_prv.append(day) 
  #print(day, day_prv, DP)
  
if DP[0] == K:
  val = DP[0]
  day_start = 0
  ct = 0
  while day_start < N:
    day = day_start
    while day < N and DP[day] != val-1:
      if DP[day] == val:
        ct += 1
      day += 1 
      #print(day, ct)
    if ct == 1:
      print(day_start+1)
    day_start = max(day, day_start + C)
    while day_start < N and DP[day_start] == -1:
      day_start += 1  
    #print(day, ct, val, day_start)
    ct = 0
    val -= 1



Measured memory_bytes: 101680
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<59)


signed main(){
    int n,m;
    while(cin>>n>>m&&(n|m)){
        vector<int> one(n,0);
        vector<int> sum(n,0);
        rep(i,m){
            int score, k;
            cin>>score>>k;
            vector<int> v(k);
            rep(j,k)cin>>v[j];
            if(k==1)one[v[0]-1]+=score;
            rep(j,k){
                sum[v[j]-1]+=score;
            }
        }

        int ans = 0;
        rep(i,n){
            rep(j,n){
                if(i==j)continue;
                ans = max(ans,sum[i]-one[j]);
            }
        }
        cout<<ans+1<<endl;
    }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
 {
    int t=1;
    while(t--){
        long long int x,k,d,l,r;
        cin>>x>>k>>d;
        x=abs(0-x);
        long long int s=x/d;
        if(s>k){
            cout<<abs(0-(x-d*k));
            return 0;
        }
        x=x-(s)*d;
        k=k-s;
        r=abs(x-0);
        x=x-d;
        l=abs(x-0);
        if(k%2==0)
        {
            cout<<r;
        }
        else
            cout<<l;
       
    }
	return 0;
}

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

int main()
{
    int a,b;
    string s;
    cin>>a>>b;
    cin>>s;
    int flag=0;
    for(int i=0;i<=a+b;i++)
    {
        if(i==a&&s[i]!='-')
        {
            cout<<"No"<<endl;
            return 0;
        }
        if(i!=a&&(s[i]<'0'||s[i]>'9'))
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
F = [ list(map(int, input().split())) for _ in range(N)]
P = [ list(map(int, input().split())) for _ in range(N)]

res = -(1<<30)

for b in range(1,1<<10):
  cc = 0
  for i in range(N):
    c = 0
    for j in range(10):
      if (b>>j&1) & F[i][j]:
        c+=1
    cc += P[i][c]
  if res<cc:
    res = cc
    
print(res)


Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using namespace std;
 
int main(){
		int m,d;cin>>m>>d;
		int cnt=0;
		for(int i=1;i<=m;i++){
				for(int j=2;j<10;j++){
						if(i%j==0 && i/j <10 && i/j>1 && 10*j+i/j<=d)cnt++;

		}}
		
		cout<<cnt<<endl;
		
		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <utility>
using namespace std;

typedef long long ll;

int main(){
  int n; cin >> n;
  pair<int, int> a[n+1];
  for(int i=1; i<=n; i++) {
    int tmp;
    cin >> tmp;
    a[i] = make_pair(tmp, i);
  }

  sort(a+1, a+n+1);

  int ans[n+1];
  for(int i=1; i<=n; i++){
    if(i<=n/2){
      ans[a[i].second] = a[n/2+1].first;
    }
    else{
      ans[a[i].second] = a[n/2].first;
    }
  }

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

  return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());

int vt[]={-1,0,1};
int vy[]={-2,-2,-2,-1,-1,0,0,1,1,2,2,2};
int vx[]={-1,0,1,-2,2,-2,2,-2,2,-1,0,1};
vector<pii> foo(pii a,pii b){
	vector<pii> ret;
	rep(i,3){
		rep(j,3){
			int x=a.F+vt[i],y=a.S+vt[j];
			
			if(-1<x&&x<10&&-1<y&&y<10){
				rep(k,12){
					int d=b.F+vx[k],e=b.S+vy[k];
					if(-1<d&&d<10&&-1<e&&e<10){
						if(d==x&&e==y){
							ret.PB(mkp(x,y));
						}
					}
				}
			}
		}
	}
	return ret;
}

int main(){
	vector<vint> vv;
	initvv(vv,10,10);
	while(1){
		vector<pii> v(1);
		cin>>v[0].F>>v[0].S;
		if(v[0].F==0&&v[0].S==0) break;
		int n;
		cin>>n;
		vector<pii> x(n);
		rep(i,n){
			cin>>x[i].F>>x[i].S;
		}
		bool f=true;
		rep(i,n){
			vector<pii> tmp;
			rep(j,v.size()){
				vector<pii> a=foo(x[i],v[j]);
				rep(k,a.size()){
					tmp.PB(a[k]);
				}
			}
			sort(ALL(tmp));
			tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
			v=tmp;
			if(v.size()==0){
				f=false;
				break;
			}
		}
		if(f) cout<<"OK\n";
		else cout<<"NA\n";
		
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p )
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v )
{
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu ()
{
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n )
{
    for(int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


int gcd(int a,int b)
{
    return b ? gcd(b,a%b) : a;
}
int lcm(int a,int b)
{
    return (a*( b/ gcd(a,b)));
}

void f()
{
    int n,k,cnt=0,a;
    cin>>n>>k;
//    for(int i=0; i<n; i++)
//    {
//        cin>>a;
//    }
    if(n==k)
    {
      cout<<1<<nl;
      return;
    }

//    if(k==2)
//    {
//      cout<<n<<nl;
//      return;
//    }

    int i=1;
    while(i<=n)
    {
      if(i+k-1>n )
        break;
      cnt++;
      i+=k-1;
    }

    if(i<n)
      cnt++;
    cout<<cnt<<nl;
}

int main()
{
    su;
    f();
    return 0;
}



Measured memory_bytes: 3636
def main():
    class MyClass:
        def __init__(self):
            self.strings = ""

        def rpl(self, int1, int2, str1):
            self.strings = self.strings[:int1] + str1 + self.strings[int2+1:]

        def rvr(self, int1, int2):
            if int1 >= 1:
                revstr = self.strings[int2:int1-1:-1]
            else:
                revstr = self.strings[int2::-1]
            self.strings = self.strings[:int1] + revstr + self.strings[int2+1:]

        def pri(self, int1, int2):
            print(self.strings[int1:int2+1])

    cls = MyClass()
    cls.strings = input()
    n = int(input())
    for _ in range(n):
        li = input().split()
        if li[0] == "replace":
            cls.rpl(int(li[1]), int(li[2]), li[3])
        elif li[0] == "reverse":
            cls.rvr(int(li[1]), int(li[2]))
        elif li[0] == "print":
            cls.pri(int(li[1]), int(li[2]))


if __name__ == "__main__":
    main()

Measured memory_bytes: 7748
from heapq import heappop, heappush

n,m=map(int,input().split())
l=[]
for _ in range(n):
    a,b=map(int,input().split())
    if a>m:continue
    l.append((a,b))

l.sort(reverse=True)

q=[]
ans=0

for i in range(1,m+1):
    while l and l[-1][0]<=i:
        a,b=l.pop()
        heappush(q,-b)
    if q:
        b=-heappop(q)
        ans+=b
print(ans)


Measured memory_bytes: 17144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	cin >>N;
            int ans =100000;
     for(int i=0;i<=N;i++){
     	int t =i;
     	int count = 0;
     	while(t>0) count += t%6,t = t/6;
            t = N-i;
            while(t>0) count += t%9,t = t/9;
            ans = min(ans,count);
     }
     cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
	int sz,n;
	int w,v,dp[1001];
	for(int k=1;scanf("%d%d",&sz,&n),sz;k++){
		memset(dp,0,sizeof(int)*1001);

		for(int i=0;i<n;i++){
			scanf("%d,%d",&v,&w);
			for(int j=sz;j>=0;j--){
				if( (j==0||dp[j]>0) && j+w<=sz )
					dp[j+w]=max(dp[j+w],dp[j]+v);
			}
		}

		int vmax=0,wmin=sz;
		for(int i=0;i<=sz;i++)
			if(vmax<dp[i] || (vmax==dp[i] && wmin>i))
				vmax=dp[i],wmin=i;
		printf("Case %d:\n%d\n%d\n",k,vmax,wmin);
	}

	return 0;
}

Measured memory_bytes: 0
/*
	ex4_2
	ruuu0048
*/
#include <stdio.h>
#include <math.h>
#define PI 3.14159265359 //πを定義
 
double radian_distance_cos(int hour,int minute); //時針と分針の間の角度の余弦を返す関数
 
int main(void){
 
 
    int hour_length,minute_length; //時針と分針の変数を宣言
    int hour,minute; //時間Hと分Mの変数を宣言
    double distance; //求める距離の変数を宣言
 
    scanf("%d %d %d %d",&hour_length,&minute_length,&hour,&minute); //それぞれ入力
    
    distance = sqrt(pow(hour_length,2) + pow(minute_length,2) - 2 * hour_length * minute_length * radian_distance_cos(hour,minute)); //余弦定理を使う
 
    printf("%.16f\n",distance); //答えを出力
 
    return 0; 
}
 
double radian_distance_cos(int hour,int minute){
 
    double hour_radian,minute_radian; //時針と分針の0時からの角度の変数を宣言
 
    hour_radian = ((double)hour + (double)minute / 60) / 12 * (2 * PI); //ラジアンに変換
 
    minute_radian = (double)minute / 60 * (2 * PI); //ラジアンに変換
 
    return cos(hour_radian - minute_radian); //差の余弦を返す
 
};


Measured memory_bytes: 2572
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int[] a = IntStream.range(0,3).map(i -> Integer.parseInt(sc.next())).sorted().toArray();
        int ans = 0;
        
        for (int i = 1; i >= 0; i--) {
            ans += (int)Math.abs(a[i] - a[i+1]);
        }
        
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 27344
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl

bool isvowel(char a)
{
    if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
     return true;
     else
        return false;
}

  int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     //ll t;
     //cin>>t;
     //while(t--)
     {
      string s;
      cin>>s;
      if((s[2]==s[3])&&(s[4]==s[5]))
       cout<<"Yes";
       else
        cout<<"No";

        cout<<endl;

     }

 return 0;
  }



Measured memory_bytes: 256
#4-c
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "+":
        z = a+b
    elif op == "-":
        z = a-b
    elif op == "*":
        z = a*b
    elif op == "/":
        z = a//b
    elif op == "?":
        break
    print(z)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
long long dp[100010],n,tot,w[110],v[110];
int main()
{
	cin>>n>>tot;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
		for(int j=tot-w[i];j>=0;j--)
		   dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
	}
	cout<<*(max_element(dp,dp+tot+1))<<endl;
	return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

int main()
{
	fast;
	int n;
	cin >> n;
	ll ans = 1;
	vll a(n);
	forn cin >> a[i];
	sort(all(a));
	// bool ok = 1;
	forn
	{
		if (a[i] == 0)
		{
			cout << 0 << en;
			return 0;
		}
		if (ans > (ll)1e18 / a[i])
		{
			cout << -1 << en;
			return 0;
		}
		ans *= a[i];
	}
	cout << ans << en;
}


Measured memory_bytes: 4000
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=a%10;
a/=100;
int c=a%10;
if(b==c) {System.out.println("Yes");}
else {System.out.println("No");}
}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
 
 int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
  while (1) {
    string x;
    cin >> x;
    if (x == "0") {
      break;
    }
    int sum = 0;
    for (int i = 0; i < x.size(); i++) {
      sum += ctoi(x[i]);
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 3156
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
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);}

typedef struct{
    ll aa;
    ll bb;
}str;
// 小大
int cmp1( const void *p, const void *q ) {
    return ((str*)p)->aa - ((str*)q)->aa;
}

int main(void){
    // char ;
    ll n,k,ans=0;
    scanf("%lld%lld",&n,&k);
    str num[n];
    rep(i,0,n){
        scanf("%lld%lld",&num[i].aa,&num[i].bb);
    }
    qsort(num,n,sizeof(str),cmp1);
    if(num[0].bb>=k){
        printf("%lld\n",num[0].aa);
        return 0;
    }
    ans+=num[0].bb;
    rep(i,1,n){
        ans+=num[i].bb;
        if(ans>=k){
            printf("%lld\n",num[i].aa);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3324
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int a[100000];
int main(void)
{
	int n;
	cin >> n;
	Rep(i, n) cin >> a[i];

	ll sum1 = 0;
	ll sum2 = 0;
	ll ans1 = 0;
	ll ans2 = 0;

	Rep(i, n){
		sum1 += a[i];
		sum2 += a[i];
		if(i % 2 == 0 && sum1 >= 0){
			ans1 += sum1 + 1;
			sum1 = -1;
		}else if(i % 2 == 1 && sum1 <= 0){
			ans1 += -sum1 + 1;
			sum1 = 1;
		}

		if(i % 2 == 1 && sum2 >= 0){
			ans2 += sum2 + 1;
			sum2 = -1;
		}else if(i % 2 == 0 && sum2 <= 0){
			ans2 += -sum2 + 1;
			sum2 = 1;
		}
	}

	PrintLn((ans1 < ans2 ? ans1 : ans2));
	return 0;
}


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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2 - x1;
    int b = y2 - y1;
    int x3, y3, x4, y4;
    x3 = x2 - b;
    y3 = y2 + a;
    x4 = x1 - b;
    y4 = y1 + a;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
import queue
q=queue.Queue()
for i in range(1,10):
    q.put(i)
while n!=1:
    x=q.get();k=x%10
    for j in [10*x+i for i in range(max(0,k-1),min(10,k+2))] :
        q.put(j)
    n-=1
print(q.get())

Measured memory_bytes: 13040
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long long A,B,C,K;
	cin >> A >> B >> C >>K;

	string s;
	//cin >> s;

	//int A[5]
	//sort(A, A + 5);
	for (long long i = 0; i < K; i++)
	{
		if (A >= B)
		{
			B *= 2;
		}
		else if (B >= C)
		{
			C *= 2;
		}
	}
	if (A < B && B < C)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

}

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

int main(){
    int64_t N, Y;
    cin >> N >> Y;
    Y /= 1000;
    int x, y, z;
    bool found = false;
    for(int i=0; i<=2000; i++){
        for(int j=0; j<=2000; j++){
            if(9*i+4*j==Y-N && N-i-j>=0){
                x=i;
                y=j;
                found = true;
                break;
            }
        }
        if(found) break;
    }
    if(found){
        cout << x << " " << y << " " << N-x-y << endl;
    }else{
        cout << "-1 -1 -1" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
from itertools import groupby 

n = int(input())

def primeFacterList(L):
    """
    L = [num]を素因数分解し、出現した素因数を(小さい順に)リストにして返す
    [2] -> [2]
    [12] -> [2, 6] -> [2, 2, 3]
    [30] -> [2, 15] -> [2, 3, 5]
    """
    num = L.pop()
    limit = int(math.sqrt(num))
    for i in range(2, limit + 1):
        if num % i == 0:
            L.append(i)
            L.append(num // i)
            return primeFacterList(L)
    else:
        L.append(num)
        return L


def calc_divisor(L):
    """
    L = [prime facter list]なる自然数の約数の個数を返す
    """
    divisor = 1
    for key, val in groupby(L):
        divisor *= (len(list(val)) + 1)
    return divisor


count = 0
for i in range(1, n+1):
    if i % 2 == 1 and calc_divisor(primeFacterList([i])) == 8:
        count += 1

print(count)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String result = "NO";
        if(isPassible(sc.nextInt(),sc.nextInt(),sc.nextInt())){
            result = "YES";
        }
        System.out.println(result);

    }

    public static boolean isPassible(int base, int divider, int mod) {
        int lcm = calcLCM(base,divider);
        int max = lcm / base;
        for(int i = 1; i <= max;i++){
            if((base * i)% divider == mod){
                return true;
            }
        }

        return false;
    }

    private static int calcLCM(int val1, int val2) {
        int maxValue = Math.max(val1, val2);
        int minValue = Math.min(val1, val2);
        long val3    = maxValue * minValue;

        if(minValue==0) return maxValue;

        int temp;
        while( (temp=maxValue%minValue)!=0 ) {
            maxValue=minValue;
            minValue=temp;
        }

        return (int)(val3/minValue);
    }
}


Measured memory_bytes: 23380
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    set<int> A;
    int d;
    for (int i = 0; i < N; i++) {
        cin >> d;
        A.insert(d);
    }

    cout << A.size() << endl;
    return 0;
}


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

int dp[100100][3];

int main(){
    int N; cin >> N;
    int a[N],b[N],c[N];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=0;i<3;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            if(j==0){
                dp[i+1][1]=max(dp[i+1][1],dp[i][0]+a[i]);
                dp[i+1][2]=max(dp[i+1][2],dp[i][0]+a[i]);
            }else if(j==1){
                dp[i+1][0]=max(dp[i+1][0],dp[i][1]+b[i]);
                dp[i+1][2]=max(dp[i+1][2],dp[i][1]+b[i]);
            }else if(j==2){
                dp[i+1][0]=max(dp[i+1][0],dp[i][2]+c[i]);
                dp[i+1][1]=max(dp[i+1][1],dp[i][2]+c[i]);
            }
        }
    }
    cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int n,m;
int main(){
	while(cin >> n >> m && n>0){
		vector<int> C;
		int P[m+5][n+5] = {0};
		for(int i=0;i<m;i++){
			int c;
			cin >> c;
			C.push_back(c);
		}
		sort(C.begin(),C.end());
		for(int i=0;i<m;i++){
			for(int j=0;j<n+1;j++){
				if(i==0){
					P[i][j] = j;
				}else if(C[i]>j){
					P[i][j] = P[i-1][j];
				}else{
					P[i][j] = min(P[i][j-C[i]]+1 , min(P[i-1][j-C[i]]+1,P[i-1][j]));
				}
			}
		}
		cout << P[m-1][n] << endl;
	}
}

#if 0
所要時間は30分程度。漸化式はすぐにたったが，実装での凡ミスが多かった。(C[i]<jとしていたなど)
#endif


Measured memory_bytes: 8012
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n;
	int p[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (p[i]!=i+1) ans ++ ;
	}
	if (ans <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

char f(char x){
  if(x=='A') return 'a';
  if(x=='B') return 'b';
  if(x=='C') return 'c';
}
int main(){
  int A,B;
  cin>>A>>B;
  string S;
  cin>>S;
  S[B-1] = f(S[B-1]);
  cout<<S<<endl;
}

Measured memory_bytes: 256
#D問題
N,K = map(int,input().split())
mod = 1000000007
pas = [[0 for i in range(j+2)] for j in range(N)]
for i in range(N):
    for j in range(i+2):
        if j == 0:
            pas[i][j] = 1
        elif j == i+1:
            pas[i][j] = 1
        else:
            pas[i][j] = pas[i-1][j-1]+pas[i-1][j]
            
for i in range(K):
    if K == 1:
        kari = 1
    else:
        kari = pas[K-2][i]
    red = N-K
    if i > red:
        ans = 0
    else:
        times = pas[red][red-i]
        ans = kari*times%mod
    print(ans)

Measured memory_bytes: 341976
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <tuple>

using namespace std;

int main()
{
    int n;
    cin >> n;
    unsigned long long t[n], a[n];
    for(int i=0; i<n; ++i) cin >> t[i] >> a[i];

    unsigned long long t_min = t[0], a_min = a[0];
    unsigned long long idx = 0;
    for(int i=1; i<n; ++i){
        idx = max((t_min-1)/t[i], (a_min-1)/a[i])+1;
        t_min = t[i]*idx;
        a_min = a[i]*idx;
    }
    cout << t_min+a_min << endl;
    return 0;
}

Measured memory_bytes: 256
//Matching
import java.util.*;
public class Main{
	static int n;
	static int[][] matrix;
	static int mod=(int)1e9+7;
	static int dp[][];
	public static int solve(int i,int mask){
		if(i==n){
		
			if(mask==0)
				return 1;
			return 0;
		}
		if(dp[i][mask]!=-1){
			return dp[i][mask];
		}
		int ans=0;

		for(int j=0;j<n;j++){
			int avai=mask&(1<<(j));
			if(matrix[i][j]==1&&avai!=0){
				ans=(ans+solve(i+1,mask&(~(1<<j))))%mod;

			}
		}
		return dp[i][mask]=ans;

	}
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		n=s.nextInt();
		matrix=new int[n][n];
		int finalBits=((1<<n)-1);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				matrix[i][j]=s.nextInt();
			}
		}
		dp=new int[n][(1<<n)];
		for(int[] x:dp){
			Arrays.fill(x,-1);
		}
		System.out.println(solve(0,finalBits));
	   }
	}

Measured memory_bytes: 197204
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e8 + 42;
int F[100001];

int main()
{

	int n, k;
	scanf("%d%d", &n, &k);
	int h[n];
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &h[i]);
	}
	F[0] = 0;
	F[1] = abs(h[1]-h[0]);
	for(int i = 2; i < n; i++)
	{
		F[i] = abs(h[i] - h[i-1] ) + F[i-1];
		for(int j = 1; j < k; j++)
		{
			if( i - j - 1 < 0) break;
			int mn = min( F[i-j] + abs(h[i]-h[i-j]) , F[i-j-1] + abs(h[i]-h[i-j-1]) );
			F[i] = min(mn, F[i]);
		}
			
	}
	
	cout<<F[n-1];
}

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

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

	    
      long long n,i,j,k,sum=0,count=0,ans=0,x=0,y=0,l,r;
      cin>>n;
      cout<<n+n*n+n*n*n;
	return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nks = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nks[0];
        var k = nks[1];
        var s = nks[2];

        Console.WriteLine(string.Join(" ", Enumerable.Repeat(s, k).Concat(Enumerable.Repeat(s == ((int)1e9) ? s - 1 : s + 1, n - k))));
    }
}

Measured memory_bytes: 22748
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,m = map(int,readline().split())
s = input()
mp = map(int,read().split())

r = list(range(n))
for i,j in zip(mp,mp):
    if r[i-1] < j-1:
        r[i-1] = j-1

for i in range(1,n):
    if r[i] < r[i-1]: r[i] = r[i-1]

zero = [0]*n
one = [0]*n
for i in range(n):
    zero[i] = zero[i-1]
    one[i] = one[i-1]
    if s[i]=="0": zero[i] += 1
    else: one[i] += 1


#print(r)
#print(s)
#print(zero)

MOD = 10**9+7
dp = [0]*n
dp[0] = 1
for i in range(n):
    L = max(zero[r[i]] + i - r[i],0)
    R = min(zero[r[i]],i+1)
    ndp = [0]*n

    for i in range(L,R+1):
        if i: ndp[i] += dp[i-1]
        ndp[i] += dp[i]
        ndp[i] %= MOD        
    dp = ndp


    #print(L,R,r[i],zero[r[i]],dp)
print(sum(dp))












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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	string S; cin >> S;

	int N = S.size();
	vi ans (N);

	int j;

	j = 0;
	for (int i = 0; i < N - 1; ++i) {
		if (S[i] == 'L') continue;
		while (S[j] == 'R' || j <= i) ++j;
		ans[j - ((j - i)%2 == 1)]++;
	}
	
	j = N-1;
	for (int i = N - 1; i > 0; --i) {
		if (S[i] == 'R') continue;
		while (S[j] == 'L' || j >= i) --j;
		ans[j + ((i - j)%2 == 1)]++;
	}

	for (int i = 0; i < N; ++i) cout << ans[i] << " ";
	cout << endl;

}

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

vector<int> L[100010];
vector<int> R[100010];
int check[100000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int l, r;
		cin >> l >> r;
		l--, r--;
		L[l].push_back(i);
		R[r].push_back(i);
	}

	set<int> cur;
	int ans = 0;
	for(int i = 0; i < N; i++){
		for(auto r : R[i]){
			if(check[r]) continue;
			for(auto v : cur){
				check[v] = 1;
			}
			cur.clear();
			ans++;
			break;
		}

		for(auto l : L[i]){
			cur.insert(l);
		}
	}
	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    sort(all(s));

    string ans = "";
    rep(i, n) ans += s[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
long long MOD=1e9+7;
long long fac[2000005], inv[2000005];
long long modpow(long long x,long long e){
	if(x==1||e==0) return 1;
	long long c=modpow(x,e/2);
	long long c1=(c*c)%MOD;
	if(e%2==0) return c1;
	else return (c1*x)%MOD;
}
long long C(long long n, long long k){
	if(k>n || k<0) return 0;
	return ((fac[n]*inv[k])%MOD*inv[n-k])%MOD;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fac[0]=inv[0]=1;
	for(int i=1;i<2000005;i++){
		fac[i]=(fac[i-1]*i)%MOD;
		if(i<1000005) inv[i]=(inv[i-1]*modpow(i, MOD-2))%MOD;
	}
	int k, n;
	string s;
	cin>>k>>s;
	n=s.size();
	long long ans=0;
	for(int i=n;i<=n+k;i++){
		long long add=(C(i-1, n-1)*modpow(25, i-n))%MOD;
		add=(add*modpow(26, n+k-i))%MOD;
		ans=(add+ans)%MOD;
	}
	cout<<ans;

}

Measured memory_bytes: 27708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2005;
ll a[maxn][maxn];
ll b[maxn][maxn];
string s[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>s[i];
    }
    for(int i=0;i<n;++i){
        ll tmp=0;
        for(int j=0;j<m;++j){
            if(s[i][j]=='.')tmp++;
            else tmp=0;
            a[i][j]=tmp;
        }
    }
    for(int j=0;j<m;++j){
        ll tmp=0;
        for(int i=0;i<n;++i){
            if(s[i][j]=='.')tmp++;
            else tmp=0;
            b[i][j]=tmp;
        }
    }
    ll mx=-1;
    for(int i=n-1;i>=0;--i){
        for(int j=m-1;j>=0;--j){
            if(j<m-1&&a[i][j])
            a[i][j]=max(a[i][j],a[i][j+1]);
            if(i<n-1&&b[i][j])
            b[i][j]=max(b[i][j],b[i+1][j]);
            mx=max(mx,(a[i][j]+b[i][j]-1));
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 67200
n=int(input())
a=list(map(int, input().split()))
if 0 in a:
  print(0)
else:
  ans=1
  a.sort(reverse=True)
  for i in range(n):
    ans*=a[i]
    if ans>10**18:
      ans=-1
      break
  print(ans)

Measured memory_bytes: 21596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

#define bampei 4100

int main() {
    string a, bb, c;
    cin >> a >> bb >> c;
    string b;
    rep(i,bampei)b += '?';
    b += bb;
    rep(i,bampei)b += '?';
    int n = a.size();
    int m = b.size();
    int w = c.size();

    int ans = 10001;

    vector<int> u, v;
    int f[50000] = {};

    rep(i,m-2000){
        int flag = 1;
        rep(j,n){
            if(a[j] != '?' && b[i+j] != '?' && a[j] != b[i+j]){
                flag = 0;
                break;
            }
        }
        if(flag)u.push_back(i);
    }

    rep(i,m-2000){
        int flag = 1;
        rep(j,w){
            if(c[j] != '?' && b[i+j] != '?' && c[j] != b[i+j]){
                flag = 0;
                break;
            }
        }
        if(flag)v.push_back(i);
    }

    rep(i,50000){
        if(i < 20000 && 20000 - i >= w){
            f[i] = 1;
            continue;
        }
        if(20000 < i && i - 20000 >= n){
            f[i] = 1;
            continue;
        }
        int flag = 1;

        rep(j,n){
            if(j-(i-20000) < 0)continue;
            if(j-(i-20000) >= w)continue;
            if(a[j] != '?' && c[j-(i-20000)] != '?' && a[j] != c[j-(i-20000)]){
                flag = 0;
                break;
            }
        }

        if(flag)f[i] = 1;
    }

    rep(i,u.size()){
        rep(j,v.size()){
            if(f[v[j] - u[i] + 20000] == 1){
                int l = min(bampei, min(u[i], v[j]));
                int r = max(bampei+(int)bb.size(),max(u[i]+n, v[j]+w));
                ans = min(ans, r - l);
                
            }
        }
    }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  long long H;
  long long W;
  
  cin >> H >> W;
  
  long long num = 0;
  
  long long num2;
  
  if(H == 1 || W == 1){
    cout << 1 << endl;
  }
  else{
  if(H % 2LL == 0LL){
    cout << H / 2LL * W << endl;
  }
  else{
    for(long long i = 0LL;i < W;++i){
      if(i % 2LL == 0LL){
        num2 = H / 2LL + 1LL;
        num = num2 + num;
      }
      else{
        num2 = H / 2LL;
        num = num + num2;
      }
    }
    cout << num << endl;
  }
  }
}
        



Measured memory_bytes: 256
def resolve():
    N = int(input())
    evdi = [[] for _ in range(N)]
    for i in range(N):
        cnt = int(input())
        for _ in range(cnt):
            x, y = map(int, input().split())
            x -= 1
            evdi[i].append((x, y))

    ans = 0
    for bit in range(1 << N):
        ok = True
        for i in range(N):
            if bit >> i & 1:
                for (x, y) in evdi[i]:
                    if y == 1 and not bit >> x & 1:
                        ok = False
                        break
                    if y == 0 and bit >> x & 1:
                        ok = False
                        break
        cnt = bin(bit).count("1")
        if ok:
            ans = max(cnt, ans)
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9160
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
	cin.sync_with_stdio(false);
	ll N;
	cin >> N;

	vector<int> primes{ 2 };
	map<int, int> factors_map;
	FOR(n, 1, N + 1) {
		int n2 = n;
		for (auto p : primes) {
			while (n2 % p == 0) {
				n2 /= p;
				factors_map[p]++;
			}
		}
		if (n2 != 1) {
			factors_map[n2]++;
			primes.pb(n2);
		}
	}
	//for (auto p : primes) cout << p << ","; cout << endl;
	//for (auto kv : factors_map) cout << kv.first << ": " << kv.second << endl;

	vector<pair<int, int>> factors;
	for (auto kv : factors_map) factors.push_back(kv);

	auto ans = 0;
	// 75
	for (auto kv : factors) {
		auto num = kv.second;
		if (num >= 74) ++ans;
	}
	// 25, 3
	for (auto kv : factors) {
		auto factor = kv.first;
		auto num = kv.second;
		if (num >= 24) {
			for (auto kv2 : factors) {
				auto factor2 = kv2.first;
				auto num2 = kv2.second;
				ans += (factor != factor2) && num2 >= 2;
			}

		}
	}
	// 15, 5
	for (auto kv : factors) {
		auto factor = kv.first;
		auto num = kv.second;
		if (num >= 14) {
			for (auto kv2 : factors) {
				auto factor2 = kv2.first;
				auto num2 = kv2.second;
				ans += (factor != factor2) && num2 >= 4;
			}

		}
	}
	// 3, 5, 5
	REP(i, SIZE(factors)) {
		auto factor1 = factors[i].first;
		auto num1 = factors[i].second;
		REP(j, SIZE(factors) - 1) {
			auto factor2 = factors[j].first;
			auto num2 = factors[j].second;
			FOR(k, j + 1, SIZE(factors)) {
				auto factor3 = factors[k].first;
				auto num3 = factors[k].second;
				if (i == j || i == k) continue;
				if (num1 >= 2 && num2 >= 4 && num3 >= 4) {
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

    static class DPatisserieABC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            long[] x = new long[n];
            long[] y = new long[n];
            long[] z = new long[n];
            for (int i = 0; i < n; i++) {
                x[i] = in.nextLong();
                y[i] = in.nextLong();
                z[i] = in.nextLong();
            }
            long mv = 0;
            for (int xd : new int[]{1, -1}) {
                for (int yd : new int[]{1, -1}) {
                    for (int zd : new int[]{1, -1}) {
                        long v = 0;
                        long[] t = new long[n];
                        for (int i = 0; i < n; i++) {
                            t[i] = (x[i] * xd) + (y[i] * yd) + (z[i] * zd);
                        }
                        Arrays.sort(t);
                        for (int i = t.length - 1; Math.max(0, t.length - m) <= i; i--) {
                            v += t[i];
                        }
                        mv = Math.max(mv, v);
                    }
                }
            }
            out.println(mv);
        }

    }
}



Measured memory_bytes: 25804
// Problem : C - XYZ Triplets
// Contest : AtCoder - エイシング プログラミング コンテスト 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

int n, m;
int t[N];

int main()
{
    //File("");
    for (int i = 1; i <= 100; i+=1)
    	for (int j = 1; j <= 100; j+=1)
    		for (int k = 1; k <= 100; k+=1)
    			++t[i * i + j * j + k * k + i * j + i * k + j * k];
    n = gi();
    for (int i = 1; i <= n; i+=1) printf("%d\n", t[i]);
    return 0;
}

Measured memory_bytes: 3848
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	ll n, m;
	cin >> n >> m;
	ll pt = 1900 * m + 100 * (n - m);
	ll fctr = (1 << m);
	cout << fctr * pt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

main()
{
  int N,A,B;
  scanf("%d",&N);
  if(N==1)
    printf("Hello World\n");
  else
  {
    scanf("%d",&A);
    scanf("%d",&B);
    printf("%d\n",A+B);
  }
}

Measured memory_bytes: 128