akhauriyash/Code-Regression huggingface dataset:
//二次元幾何ライブラリ
#include <iostream>
#include <complex>
#include <map>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define x(a) (a).real()
#define y(a) (a).imag()
typedef long double D;
typedef bool B;
typedef complex<D> P;   //点
typedef complex<D> V;   //ベクトル
typedef pair<P,P>  L;   //直線
typedef pair<P,D>  C;   //円
typedef vector<P>  Pol; //多角形

//変数名定義
const D INF = 1e100;
const D EPS = 1e-8;
const D PI = acos(-1);

template<class T> bool operator==(T a, T b){return abs(a - b )< EPS;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}

  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }

// ベクトルaの絶対値を求める
// D Length = abs(a);

// 2点a,b間の距離を求める
// D Distance = abs(a-b); 

// 内積 (Inner Product) : a・b = |a||b|cosθ
D IP(V a, V b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// 外積 (Exterior Product) : a×b = |a||b|sinθ
D EP(V a, V b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

// 2直線の直交判定 : a⊥b <=> IP(a, b) = 0
B IsVecular(P a1, P a2, P b1, P b2) {
	return IP(a1-a2, b1-b2)==0.0;
}

// 2直線の平行判定 : a//b <=> EP(a, b) = 0
B IsParallel(P a1, P a2, P b1, P b2) {
	return EP(a1-a2, b1-b2)== 0.0;
}


// 点と直線の距離 (Distance of Point and Line)  //l1の構造 x座標 first<second y座標 first>second 右上 正 左下 負 一致の
D  DPL(P p,L l){
	V v1=(p-l.first);
	V v2=(l.second-l.first);
	return EP(v1,v2)/abs(v1);
}

// 三角形の領域判定 Teritory of Triangle 内部のみ
B TT(P p1,P p2,P p3,P p){
	L l1,l2,l3;
	l1=make_pair(p2,p3);
	l2=make_pair(p3,p1);
	l3=make_pair(p1,p2);

	if(sig(DPL(p1,l1))!=sig(DPL(p,l1)))
		return false;
	else if(sig(DPL(p2,l2))!=sig(DPL(p,l2)))
		return false;
	else if(sig(DPL(p3,l3))!=sig(DPL(p,l3)))
		return false;
	else
		return true;
}


//変数名 = 型 代入したいもの
//example : v1 = V(5.0,-3.0) p1=P(0.0,4.0)
int main(void){
	int n;
	cin >>n; 
	rep(i,n){
		P point[5];	
		rep(j,5)
		cin >> point[j].real() >> point[j].imag() ;
		if (TT(point[0],point[1],point[2],point[3])==TT(point[0],point[1],point[2],point[4]))
			cout << "NG" << endl;
		else
			cout << "OK" << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std; 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
# define M_PI           3.14159265358979323846
#define vec vector 
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=dp[0]+abs(arr[0]-arr[1]);
    for(ll i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1] + abs(arr[i-1]-arr[i]), dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    cout<<dp[n-1]<<"\n";
    return 0;     
}

Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define PI pair<int,int>

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = (ll)(1e9 + 7);
const int N = 1000010;


int main() {    
    string str;
    int K;
    while (cin >> K >> str) {
        int n = str.length();
        if (n <= K) cout << str << endl;
        else cout << str.substr(0, K) + "..." << endl;
    }
    return 0;
}
    


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a,b,c; cin>>a>>b>>c;
  int min;
  min = a+b;
  if(min>b+c){
    min=b+c;
  }
  if(min>a+c){
    min=a+c;
  }
  cout<<min<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 998244353
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long




void solve()
{
    int n;
    int k;
    cin>>n>>k;
    vector<pll>v;
    for(int i=0;i<k;i++)
    {
        int l,r;
        cin>>l>>r;
        
        v.pb({l,r});
    }
    int dp[n*4]={};
    
    dp[1]=1;
    
    for(int i=1;i<=n+5;i++)
    {
        if(i>2){
        dp[i]+=dp[i-1];
        }
        
        int cur=dp[i]%mod;
        for(int j=0;j<k;j++)
        {
            dp[i+v[j].first]+=cur;
            dp[i+v[j].second+1]-=cur;
        }
        
    }
    
    cout<<dp[n]%mod;
    
    
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}

Measured memory_bytes: 9840
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> d(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> d[i];
	}
	sort(d.begin(), d.end());

	auto result = 1;
	for (auto i = 1; i < N; ++i)
	{
		if (d[i] > d[i - 1])
		{
			++result;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define TR(it,c) for( typeof(c.begin()) it = c.begin(); it != c.end(); ++it )
#define TRR(it,c) for( typeof(c.rbegin()) it = c.rbegin(); it != c.rend(); ++it
#define REP(i,a) for (int i = 0; i < (a); i++)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)

#define DRI(a) int a; scanf("%d", &a);
#define DRII(a, b) int a, b; scanf("%d %d", &a, &b);
#define DRIII(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c);
#define RI(a) scanf("%d", &a);
#define RII(a, b) scanf("%d %d", &a, &b);
#define RIII(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define MM(arr, num) memset((arr), (num), sizeof((arr)))
#define DEB(x) cerr << ">>> " << (#x) << " -> " << (x) << endl;
#define DEBA(x,n) cerr << (#x) << " "; deba((x),(n));
void deba(int * a, int n){ cerr << "| "; REP(i,n) cerr << a[i] << " "; cerr << "|" << endl;}


inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

const int INF = 1<<30;
typedef long long ll;
typedef unsigned long long ull;
/*******************************************************/
char s[1234560];

int main() {

  scanf("%s",s);
  int len = strlen (s);
  REP(i,len){
    if(i>0) if(s[i-1] == s[i]){ cout << i << " " << i+1 << endl; return 0;}
    if(i>1) if(s[i-2] == s[i]){ cout << i-1 << " " << i+1 << endl; return 0;}


  }

  cout << "-1 -1" << endl;

  return 0;
}


Measured memory_bytes: 384
// Problem : B - Frog 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define MM			1000000007
#define N			100005
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define Endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for(int i=begin;i<end;i++)
#define repr(i,begin,end) for(int i=end-1;i>=begin;i--)
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 			resize
 
 
 
signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n,k;
		cin>>n>>k;
		int a[n+1];
		rep(i,1,n+1) cin>>a[i];
		int dp[n+1][k+1];
		rep(i,0,n+1) rep(j,0,k+1) dp[i][j]=INT_MAX;
		rep(i,0,k+1) dp[1][i]=0;
		rep(i,2,n+1)
		{
		    rep(j,1,k+1)
		    {
		        if(i-j>=1)
		        {
		            rep(l,1,k+1)
		            {
		                dp[i][j]=min(dp[i-j][l]+abs(a[i]-a[i-j]),dp[i][j]);
		            }
		        }
		    }
		}
		int ans=INT_MAX;
		rep(i,1,k+1) ans=min(ans,dp[n][i]);
		cout<<ans;
	}
}

Measured memory_bytes: 83264
/* ITP1_10_D */
#include <stdio.h>
#include <math.h>

/* short???????????????????????¢??° */
void init_array_short(short array[], short size);
/* ???????????????????????¢?????????????????¢??° */
double get_manhattan_dis(short v_x[], short v_y[], short dim);
/* ???????????????????????¢?????????????????¢??° */
double get_euclid_dis(short v_x[], short v_y[], short dim);
/* p = 3??´????????????????????????????????¢?????????????????¢??° */
double get_minkowski_dis_p3(short v_x[], short v_y[], short dim);
/* ?????§????????§????????¢?????????????????¢??° */
double get_chebyshev_dis(short v_x[], short v_y[], short dim);

int main(void)
{
	// ?¬??????°?????\???
	short dim = 0;
	scanf("%hd", &dim);
	
	short ii;
	
	short vec_x[dim];
	init_array_short(vec_x, dim);
	
	for( ii = 0; ii < dim; ii++ )
	{
		scanf("%hd", &vec_x[ii]);
	}
	
	short vec_y[dim];
	init_array_short(vec_y, dim);
	
	for( ii = 0; ii < dim; ii++ )
	{
		scanf("%hd", &vec_y[ii]);
	}
	
	// ???????????????????????¢?????????????????¨???
	printf("%lf\n", get_manhattan_dis(vec_x, vec_y, dim));
	
	// ???????????????????????¢?????????????????¨???
	printf("%lf\n", get_euclid_dis(vec_x, vec_y, dim));
	
	// p = 3?????¨????????????????????????????????¢?????????????????¨???
	printf("%lf\n", get_minkowski_dis_p3(vec_x, vec_y, dim));
	
	// ?????§????????§????????¢?????????????????¨???
	printf("%lf\n", get_chebyshev_dis(vec_x, vec_y, dim));
	
	return 0;
}

/* short???????????????????????¢??° */
void init_array_short(short array[], short size)
{
	short ii;
	for( ii = 0; ii < size; ii++ )
	{
		array[ii] = 0;
	}
}

/* ???????????????????????¢????????? */
double get_manhattan_dis(short v_x[], short v_y[], short dim)
{
	short ii;
	double result = 0.0;
	for( ii = 0; ii < dim; ii++ )
	{
		result += fabs(v_x[ii] - v_y[ii]);
	}
	return result;
}

/* ???????????????????????¢????????? */
double get_euclid_dis(short v_x[], short v_y[], short dim)
{
	short ii;
	double result = 0.0;
	for( ii = 0; ii < dim; ii++ )
	{
		result += pow(fabs(v_x[ii] - v_y[ii]), 2);
	}
	return sqrt(result);
}

/* p = 3?????´????????????????????????????????¢????????? */
double get_minkowski_dis_p3(short v_x[], short v_y[], short dim)
{
	short ii;
	double result = 0.0;
	for( ii = 0; ii < dim; ii++ )
	{
		result += pow(fabs(v_x[ii] - v_y[ii]), 3);
	}
	return cbrt(result);
}

/* ?????§????????§????????¢????????? */
double get_chebyshev_dis(short v_x[], short v_y[], short dim)
{
	short ii;
	double result = 0.0;
	double temp = 0.0;
	for( ii = 0; ii < dim; ii++ )
	{
		temp = fabs(v_x[ii] - v_y[ii]);
		if( temp > result )
		{
			result = temp;
		}
	}
	return result;
}

Measured memory_bytes: 708
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    l = [0] * N
    for i, v in enumerate(A):
        l[v - 1] = i + 1
    print(' '.join([str(i) for i in l]))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25284
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, M, V, P;
vector<ll> A;
bool check(ll m)
{
  if (m < P)
  {
    return true;
  }
  if (A.at(m) + M < A.at(P - 1))
  {
    return false;
  }
  ll s = 0;
  s += M * (P - 1 + N - m);
  for (int i = P - 1; i < m; ++i)
  {
      s += max(0ll, A.at(m) + M - A.at(i));
  }
  if (s >= M * V)
  {
    return true;
  }
  return false;
}


int main()
{
  cin >> N >> M >> V >> P;
  A = vector<ll>(N);
  for (ll i = 0; i < N; ++i)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  // cout << "A" << endl;
  // for (ll i = 0; i < N; ++i)
  // {
  //   cout << A.at(i) << ' ';
  // }
  // cout << endl;
  ll l = -1, r = N;
  ll m;
  while (l + 1 != r)
  {
    m = (l + r) / 2;
    if (check(m))
    {
      l = m;
    }
    else
    {
      r = m;
    }
  }
  cout << l + 1 << endl;
  // cout << "l" << l << endl;
}


Measured memory_bytes: 1024
numList = input().split()
n = int(numList[0])
m = int(numList[1])
a = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]
c = [0 for i in range(n)]

for i in range(n):
    arrayList = input().split()
    for j in range(m):
        a[i][j] = int(arrayList[j])

for i in range(m):
    b[i] = int(input())

for i in range(n):
    for j in range(m):
        c[i] += (a[i][j] * b[j])
    print(c[i])


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

int main () {
    int H,W;
    cin >> H >> W;
    char mat[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> mat[i][j];
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cout << mat[i][j];
        }
        cout << '\n';
        for(int j=0; j<W; j++){
            cout << mat[i][j];
        }
        cout << '\n';
    }
}



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


int main() {
  int x, a, b;
  cin >> x >> a >> b;
  int ans = (x - a) % b;
  cout << ans << endl;
  return 0;
  
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if (n%x==0) {
        int ans = n/x*t;
        cout << ans << endl;
    }
    else {
        int ans = (n/x+1)*t;
        cout << ans << endl;
    }
}


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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int n=1;
  vector<int> cd(100,0);
  int j=0;
  for(int i=0; i<min(a,b); i++){
    if(a%n == 0 && b%n == 0){
      cd[j] = n;
      j++;
    }
    n++;
  }
  sort(cd.begin(),cd.end());
  cout << cd[100-k] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c,x;
    cin >> a >> b >> c >> x;
    int64_t res = 0;
    rep(i,a+1){
        rep(j,b+1){
            int64_t remain = x - i*500 - j*100;
            if(remain < 0) break;
            if(remain/50<=c) res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i + 100*j + 50*k) ==X:
                ans += 1

print(ans)

Measured memory_bytes: 9136
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))

from bisect import bisect_left


def solve():
    N, K = map(int, input().split())

    As = list(map(int, input().split()))

    As.sort()
    index = bisect_left(As, 0)

    # neg = As[:index]
    # pos = As[index:]
    # pos = pos[bisect_left(pos, 1):]
    # pos.sort(reverse=True)
    # print(pos, neg)

    pos = sorted(As, reverse=True)
    ans = 1
    mod = 10 ** 9 + 7

    if N == K:
        for p in pos:
            ans *= p
            ans %= mod
        return ans

    if index == N and K % 2:
        for p in pos[:K]:
            ans *= p
            ans %= mod
        return ans

    pl = 0
    pr = N - 1

    for i in range(K//2):
        left = pos[pl] * pos[pl+1]
        right = pos[pr] * pos[pr-1]

        if left > right:
            ans *= left
            ans %= mod
            pl += 2
        else:
            ans *= right
            ans %= mod
            pr -= 2

    if K % 2:
        ans *= max(pos[pl], pos[pr])
        ans %= mod

    return ans


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 30744
import re

N = 1
while True:
    N = int(input())
    if not N:
        break
    tmp, groups, firstgroup = [], {}, []
    for i in range(N):
        tmp = re.split(r"[\,\.\:]", input())
        if not i:
            firstgroup = tmp[1:]

        else:
            groups[tmp[0]] = tmp[1:]

    while True:
        change = False
        tmp = []
        for i in range(len(firstgroup)):
            if firstgroup[i] in groups:
                tmp += groups[firstgroup[i]]
                change = True
            else:
                tmp.append(firstgroup[i])

        firstgroup = ['']
        for i in tmp:
            if i not in firstgroup:
                firstgroup.append(i)

        if not change:
            break
    print(len(firstgroup) - 1)


Measured memory_bytes: 6652
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

ans = sum(A)
dp = [0]*(10**5+1)
for i in A:
    dp[i] += 1

for i in BC:
    ans += (i[1] - i[0]) * dp[i[0]]
    dp[i[1]] += dp[i[0]]
    dp[i[0]] = 0
    print(ans)


Measured memory_bytes: 32256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[2][16100];

int main() {
  string s;
  cin>>s;
  s+="T";
  ll x,y;
  cin>>x>>y;
  ll c = 0;
  ll d = 0;
  vector<vector<ll> > v(2,vector<ll>());
  rep(i,0,s.sz){
    if(s[i]=='T'){
      if(c%2==0){
        v[0].pb(d);
      }
      else{
        v[1].pb(d);
      }
      c++;
      d = 0;
    }
    else{
      d++;
    }
  }
  clr(dp,0);
  rep(i,0,2){
    if(v[i].sz==0){
      dp[i][8050] = 1;
      continue;
    }
    if(i==0){
      dp[i][8050+v[i][0]] = 1;
    }
    else{
      dp[i][8050+v[i][0]] = 1;
      dp[i][8050-v[i][0]] = 1;
    }
    rep(j,1,v[i].sz){
      ll a = v[i][j];
      ll dp1[16100];
      clr(dp1,0);
      rep(k,0,16100){
        if(dp[i][k]==1){
          dp1[k+a] = 1;
          dp1[k-a] = 1;
        }
      }
      rep(k,0,16100){
        dp[i][k] = dp1[k];
      }
    }
  }
  if(dp[0][8050+x]==1&&dp[1][8050+y]==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if((A * B) % 2 == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

		return;
	}
}


Measured memory_bytes: 22868
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var N = scan.NextInt();
        var T = scan.ArrayInt(N);
        var M = scan.NextInt();
        var sb = new StringBuilder();
        var sum = 0;
        for (int i = 0; i < N; i++) {
            sum += T[i];
        }
        for (int i = 0; i < M; i++) {
            var p = scan.NextInt() - 1;
            var x = scan.NextInt();
            Console.WriteLine(sum - T[p] + x);
        }
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}


Measured memory_bytes: 27516
n = gets.to_i
s = (1..n).map{gets.split.map(&:to_i)}
ans = []
101.times{|x|101.times{|y|
    sd = s.sort{|a, b|
        aa = (a[0] - x).abs + (a[1] - y).abs
        bb = (b[0] - x).abs + (b[1] - y).abs
        aa <=> bb
    }
    h = (sd[0][0] - x).abs + (sd[0][1] - y).abs + sd[0][2]
    ans = [x, y, h] if s.select{|v|
        v[2] != 0 || (v[0] - x).abs + (v[1] - y).abs <= h
    }.select{|v|
        (v[0] - x).abs + (v[1] - y).abs + v[2] != h}.length == 0
    }}
puts ans[0].to_s + " " + ans[1].to_s + " " + ans[2].to_s


Measured memory_bytes: 4476
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	if (N / 100 == N % 10)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int w,n,a,b,i,t,h[50];
	
	scanf("%d\n%d",&w,&n);

	for(i=1;i<=w;i++)
		h[i]=i;

	i=0;

	while(i<n)
	{
		scanf("%d,%d",&a,&b);
		t=h[a];
		h[a]=h[b];
		h[b]=t;
		i+=1;
	}
	for(i=1;i<=w;i++)
	{
	  printf("%d\n",h[i]);
	}

 return 0;
}
	

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll n,g=0;cin>>n;
for(ll i=1;i<=n;i++)
{
	for(ll j=1;j<=n;j++)
	{
		for(ll k=1;k<=n;k++)
		{
			g+=__gcd(__gcd(i,j),k);
			
		}
	}
}

cout<<g;
}



Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<map>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int cnt[4105][4105][2];
char str[10];
int n,k;
int x[100005];
int y[100005];
bool st[100005];
int calcb(int x1,int y1,int x2,int y2,int typ)
{
	return cnt[x2][y2][typ]-(x1?cnt[x1-1][y2][typ]:0)-(y1?cnt[x2][y1-1][typ]:0)+((x1 && y1)?cnt[x1-1][y1-1][typ]:0);
}
int main()
{
	read(n);
	read(k);
	for(int i=0;i<n;i++)
	{
		read(x[i]);
		read(y[i]);
		scanf("%s",str);
		st[i]=(str[0]=='B');
		cnt[(x[i]%(2*k))][y[i]%(2*k)][st[i]]++;
	}
	for(int i=0;i<2*k;i++)
		for(int j=0;j<2*k;j++)
		{
			cnt[i+2*k][j][0]=cnt[i][j][0];
			cnt[i+2*k][j][1]=cnt[i][j][1];
		}
	for(int i=0;i<4*k;i++)
		for(int j=0;j<2*k;j++)
		{
			cnt[i][j+2*k][0]=cnt[i][j][0];
			cnt[i][j+2*k][1]=cnt[i][j][1];
		}
	for(int i=0;i<4*k;i++)
		for(int j=1;j<4*k;j++)
		{
			cnt[i][j][0]+=cnt[i][j-1][0];
			cnt[i][j][1]+=cnt[i][j-1][1];
		}
	for(int i=0;i<4*k;i++)
		for(int j=1;j<4*k;j++)
		{
			cnt[j][i][0]+=cnt[j-1][i][0];
			cnt[j][i][1]+=cnt[j-1][i][1];
		}
	int ans=0;
//	for(int i=0;i<4;i++)
//		for(int j=0;j<4;j++)
//			cout<<i<<" "<<j<<' '<<calcb(i,j,i+k-1,j+k-1,0)+calcb(i+k,j,i+k+k-1,j+k-1,1)+calcb(i,j+k,i+k-1,j+k+k-1,1)+calcb(i+k,j+k,i+k+k-1,j+k+k-1,0)<<endl;
	for(int i=0;i<2*k;i++)
		for(int j=0;j<2*k;j++)
			ans=max(ans,calcb(i,j,i+k-1,j+k-1,0)+calcb(i+k,j,i+k+k-1,j+k-1,1)+calcb(i,j+k,i+k-1,j+k+k-1,1)+calcb(i+k,j+k,i+k+k-1,j+k+k-1,0));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 131328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] c1 = scanner.next().toCharArray();
			char[] c2 = scanner.next().toCharArray();
			int n = c1.length;
			boolean result = false;
			if (n == c2.length) {
				result = true;
				for (int i = 0; i < n; i++) {
					if (c1[i] != c2[n - 1 - i]) {
						result = false;
						break;
					}
				}
			}
			System.out.println(result ? "YES" : "NO");
		}
	}
}


Measured memory_bytes: 23252
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,bool> B;
typedef pair<P,B> PP;
int W,H,N;
char fie[33][33];
int mie[33][33];
int ine[33][33];
vector<PP> q;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
void prfie(){
  for(int i=0;i<(int)q.size();i++){
    cout << q[i].first.first << " "<<q[i].first.second<<" : "<<q[i].second.first<<endl; 
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++)
      cout << mie[j][i] << " ";
    cout << endl;
  }
  cout << endl;
  getchar();
}
int solve(){
  int turn=0;
  while(turn<=180 && N>0){
    ++turn;
    //    prfie();
    memset(ine,-1,sizeof(ine));
    for(int i=0;i<(int)q.size();i++){
      if(q[i].second.second) continue;
      for(int j=0;j<4;j++){
	PP p = q[i];
	int nx=(p.first.first)+dx[(p.second.first+j)%4];
	int ny=-p.first.second+dy[(p.second.first+j)%4];
	if(fie[nx][ny]!='#' && mie[nx][ny]==0){
	  q[i].second.first=(p.second.first+j+3)%4;
	  mie[p.first.first][-p.first.second]=q[i].second.first+1;
	  int nw=q[i].second.first;
	  if(nw==2) ine[nx][ny]=nw;
	  else if(ine[nx][ny]==2){}
	  else if(nw==3) ine[nx][ny]=nw;
	  else if(ine[nx][ny]==3){}
	  else if(nw==0) ine[nx][ny]=nw;
	  else if(ine[nx][ny]==0){}
	  else ine[nx][ny]=nw;
	  //	  cout << q[i].first.first << " "<<q[i].first.second<<" : "<<q[i].second.first<<endl;   
	  break;
	}
      }
    }
    sort(q.rbegin(),q.rend());
    for(int i=0;i<(int)q.size();i++){
      if(q[i].second.second) continue;
      PP p = q[i];
      int nx=(p.first.first)+dx[(p.second.first+1)%4];
      int ny=-p.first.second+dy[(p.second.first+1)%4];
      if(!mie[nx][ny] && ine[nx][ny]==p.second.first){
	mie[p.first.first][-p.first.second]=0;
	if(fie[nx][ny]=='X'){
	  --N;
	  q[i].second.second=true;
	  continue;
	}
	mie[nx][ny]=p.second.first+1;
	q[i]=PP(P(nx,-ny),B(p.second.first,false));
      }
    }
    
  }
  q.clear();
  return turn;
}
main(){
  while(1){
    cin >> W >> H;
    if(!W && !H) break;
    N=0;
    memset(mie,0,sizeof(mie));
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >>fie[j][i];
	if(fie[j][i]=='#')
	  mie[j][i]=9;
	if(fie[j][i]=='E'){
	  q.push_back(PP(P(j,-i),B(0,false)));
	  mie[j][i]=1;
	}else if(fie[j][i]=='N'){
	  q.push_back(PP(P(j,-i),B(1,false)));
	  mie[j][i]=2;
	}else if(fie[j][i]=='W'){
	  q.push_back(PP(P(j,-i),B(2,false)));
	  mie[j][i]=3;
	}else if(fie[j][i]=='S'){
	  q.push_back(PP(P(j,-i),B(3,false)));
	  mie[j][i]=4;
	}
      }
    }
    N=(int)q.size();
    int res=solve();
    if(res>180) cout <<"NA"<<endl;
    else cout << res << endl;
  }
}

Measured memory_bytes: 1216
///spaesk

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define pi acos(-1)
#define int long long int
#define ld long double
#define ar array
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1003;

///
///

void solve()
{

    string a, b;
    cin>>a>>b;
    int ans = 0;
    for(int i = 0; i < a.size(); i ++) {
        if(a[i] != b[i])
            ans ++;
    }
    cout<<ans;
    cout<<"\n";
    return ;
}

/*
*/

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;
using p = pair<ll,  ll>;
using pp = pair<pair<ll, ll>, pair<ll, pair<ll, ll>>>;

int main () {
	ll n, m, k;
	cin >> n >> m >> k;
	ll ar[n], br[m];
	for (ll i = 0; i < n; i++) {
		cin >> ar[i];
		if (i) {		
			ar[i] += ar[i - 1];
		}
	}
	for (ll i = 0; i < m; i++) {
		cin >> br[i];
		if (i) {
			br[i] += br[i - 1];
		}
	}
	ll ma = upper_bound (br, br + m, k) - br;
	for (ll i = 0; i < n; i++) {
		if (k >= ar[i]) {
			ma = max (i + 1 + ll(upper_bound (br, br + m, k - ar[i]) - br), ma);
		}
	}
	cout << ma << "\n";
}


Measured memory_bytes: 6744
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 5) {
		cout << 0 << endl;
	}
	else if (a <= 12) {
		cout << b / 2 << endl;
	}
	else {
		cout << b << endl;
	}

}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
#define END system("PAUSE");return 0
int n, k, a[111];
int dp[111][111111];
signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i];
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		rep(j, k + 1) {
			int x = dp[i - 1][j], y = 0;
			if (j > a[i])y = dp[i - 1][j - a[i] - 1];
			dp[i][j] = (x - y + MOD) % MOD;
		}
		for (int j = 1; j <= k; j++) {
			dp[i][j] += dp[i][j - 1];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[n][k] << endl;
	END;
}


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

using namespace std;

int main()
{
    int h,w;
    while (true)
    {
        cin>>h>>w;
        if(h==0 && w==0)
        {
            break;
        }
        for(int i=1; i<=h; i++)
        {
            for(int j=1; j<=w; j++)
            {
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 3084
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int h, w, i, j;
	cin >> h >> w;
	vector<vector<char> > a(h + 2, vector<char>(w + 2));
	for (i = 1; i <= h; i++) {
		for (j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}

	int nowi = 1, nowj = 1;
	while (nowi != h || nowj != w) {
		if (nowi == 1 && nowj == 1) {
			if (a[nowi + 1][nowj] == a[nowi][nowj + 1]) {
				cout << "Impossible" << endl;
				return 0;
			}
			else if (a[nowi + 1][nowj] == '#') {
				nowi = nowi + 1;
			}
			else {
				nowj = nowj + 1;
			}
		}
		else {
			if ((a[nowi + 1][nowj] == a[nowi][nowj + 1]) || (a[nowi - 1][nowj] == a[nowi][nowj - 1])) {
				cout << "Impossible" << endl;
				return 0;
			}
			else if (a[nowi + 1][nowj] == '#') {
				nowi = nowi + 1;
			}
			else {
				nowj = nowj + 1;
			}
		}
	}
	int cnt = 0;
	for (i = 0; i < 4; i++) {
		if (a[h + dx[i]][w + dy[i]] == '#') {
			cnt++;
		}
	}
	if (cnt == 1) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

L = ii()

p = 1
n = 0
while p <= L:
    p *= 2
    n += 1
p //= 2

ed = []
q = p
for i in range(1, n):
    q //= 2
    ed.append((i, i + 1, 0))
    ed.append((i, i + 1, q))

L -= p
off = p
p //= 2
m = 2
while L:
    if p <= L:
        ed.append((1, m, off))
        L -= p
        off += p
    p //= 2
    m += 1

print(n, len(ed))
for u, v, w in ed:
    print(u, v, w)


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

using namespace std;

vector <vector <int> > e;
vector <int> p;
int n, d[100000] = {};

bool DFS(int x, int s)
{
	p.push_back(x);
	
	if (x == n-1)
		return 1;
	
	int c = 0;
	
	for (int i = 0; i < e[x].size(); i++)
		if (e[x][i] != s)
		{
			c |= DFS(e[x][i], x);
			
			if (c)
				return 1;
		}
	
	p.pop_back();
	return 0;
}

void TES(int x, int f, int s)
{
	d[x] = f;
	
	for (int i = 0; i < e[x].size(); i++)
		if (e[x][i] != s && (d[e[x][i]] == f || d[e[x][i]] == 0))
			TES(e[x][i], f, x);
}

int main()
{	
	int a, b, v = 0, w = 0;
	cin >> n;
	e.resize(n);
	
	for (int i = 0; i < n-1; i++)
	{
		cin >> a >> b;
		e[a-1].push_back(b-1);
		e[b-1].push_back(a-1);
	}
	
	DFS(0, -1);

	for (int i = 0; i < p.size(); i++)
		d[p[i]] = (i < (p.size()+1)/2 ? 1 : 2);
	
	TES(0, 1, -1);
	TES(n-1, 2, -1);

	for (int i = 0; i < n; i++)
		d[i] == 1 ? v++ : w++;

	if (v > w)
		cout << "Fennec";
	else
		cout << "Snuke";
}

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

int main(){
	int N;
  	char s;
  	set<char>S;
  	cin>>N;
  	for(int i=0;i<N;++i){
      cin>>s;
      S.insert(s);}
	if(S.size()==4)cout<<"Four"<<endl;
  	else cout<<"Three"<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#define R(i, n) for(int i = 0; i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d",  &a, &b, &c)
#define P(a) printf("%d\n", a)
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> IR;

int N, Q;
ll K;

int main(){
	S(N);
	scanf("%lld", &K);
	S(Q);
	ll must_win;
	if(K > Q){
		R(i, N){
			printf("Yes\n");
		}
		return 0;
	}
	else {must_win = Q - K + 1;
	int ans_num[100001] = {0};
	bool is_clear[100001] = {false};
	R(i, Q){
		int n;
		S(n);
		ans_num[n]++;
		if(ans_num[n] >= must_win) is_clear[n] = true;
	}
	for(int i = 1; i <= N; i++){
		if(is_clear[i]) printf("Yes\n");
		else printf("No\n");
	}
	return 0;}
}

Measured memory_bytes: 896
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		for(;;) {
			int n = sc.nextInt(), m = sc.nextInt(), s = sc.nextInt();
			if((n|m|s) == 0) break;
			int[][] dp = new int[n*n+1][s+1];
			dp[0][0] = 1;
			for(int j=1;j<=m;j++) for(int i=n*n;i>=1;i--) for(int k=s;k>=j;k--) {
				dp[i][k] = ( dp[i][k] + dp[i-1][k-j] ) % 100000;
			}
			System.out.println(dp[n*n][s]);
		}
		// your code goes here
	}
}

Measured memory_bytes: 21188
n=int(input())
ans=[0]*4
for i in range(n):
  x=input()
  if x=='AC':
    ans[0]+=1
  elif x=='WA':
    ans[1]+=1
  elif x=='TLE':
    ans[2]+=1
  elif x=='RE':
    ans[3]+=1
print('AC x '+str(ans[0]))
print('WA x '+str(ans[1]))
print('TLE x '+str(ans[2]))
print('RE x '+str(ans[3]))


Measured memory_bytes: 69900
#dp[n][t]=max(dp[n-1][t],dp[n-1][t-A[n]]+B[n])
#dp[0][t]=0, dp[n][0]=0,0<=t<=T+max(B)-1, 0<=n<=N
def solve():
    N, T = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    X.sort()
    dp = [[0]*(T+3000) for _ in range(N+1)]
    for n in range(1,N+1):
        for t in range(1,T+X[n-1][0]):
            dp[n][t]=dp[n-1][t]
            if t>=X[n-1][0]:
                dp[n][t]=max(dp[n][t],dp[n-1][t-X[n-1][0]]+X[n-1][1])
    ans = max(dp[N])
    return ans
print(solve())

Measured memory_bytes: 183512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
int main()
{
	string s, ans = {};
	int w;
	cin >> s >> w;
	for (int i = 0; i < s.size(); i += w) {
		ans += s[i];
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> Q;

int GCD(int a, int b){ return a?GCD(b%a,a):b; }

int main(){
  string s;
  while(cin >> s){
    if(s=="#")return 0;

    Q res(0,0);

    reverse(s.begin(),s.end());
    for(int i=0;i<(int)s.size();){
      if(s[i] == 't'){
	if(res.second == 0){
	  res = make_pair(90,1);
	}else{
	  res.first = res.first * 2 + 90;
	  res.second *= 2;
	}
       
	i += 4;
      }else{
	if(res.second == 0){
	  res = make_pair(0,1);
	}else{
	  res.first = res.first * 2 - 90;
	  res.second *= 2;
	}

	i += 5;
      }
    }
    int gcd = GCD(res.first, res.second);
    res.first /= gcd; res.second /= gcd;
   
    if(res.second == 1)cout << res.first << endl;
    else cout << res.first << "/" << res.second << endl;
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair <int,int> P;

int main(){
    int N,M,C;
    cin >> N >> M >> C;
    int B[M];
    for(int i=0;i<M;i++){
        cin >> B[i];
    }

    int A[M];
    int sum = 0;
    int ans = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[j];
            sum = sum + A[j] * B[j];
        }

        sum = sum + C;
        if(sum > 0) ans = ans + 1;
        sum = 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VL A(N);
  rep(i,N) cin>>A[i];
  set<ll> S,T;
  rep(i,N) S.insert(A[i]);
  rep(qwe,N){
    if(T.find(A[qwe])!=T.end()){
      S.erase(A[qwe]);
      continue;
    }
    T.insert(A[qwe]);
    if(S.find(A[qwe])==S.end()) continue;
    rep(i,1000001/A[qwe]){
      ll tmp=A[qwe]*(i+2);
      S.erase(tmp);
    }
  }
  cout<<S.size()<<endl;
}

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

int main () {
  int n;
  std::cin >> n;
  int card[52] = {0};
  for (int i = 0; i < n; i++)
  {
    char suit;
    int num;
    std::cin >> suit >> num;
    if (suit == 'S') {
      card[num - 1] = 1;
    }
    if (suit == 'H') {
      card[13 + num - 1] = 1;
    }
    if (suit == 'C') {
      card[26 + num - 1] = 1;
    }
    if (suit == 'D') {
      card[39 + num - 1] = 1;
    }
  }
  for (int i = 0; i < 52; i++) {
    if (card[i] == 0) {
      int num = i % 13 + 1;
      if (i / 13 == 0)
      {
        std::cout << "S " << num;
      }
      if (i / 13 == 1) {
        std::cout << "H " << num;
      }
      if (i / 13 == 2) {
        std::cout << "C " << num;
      }
      if (i / 13 == 3) {
        std::cout << "D " << num;
      }
      std::cout << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3072
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n;
int a[maxn];

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

void solve()
{
    lli ans = 0;
    for(int i = 2; i <= n; ++i)
        if(a[i - 1] > a[i])
        {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 4416
package main

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

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	A := N*(N-1) + M*(M-1)
	fmt.Println(A / 2)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;
typedef long long ll;

int main(void)
{   
	ll T1,T2,A1,B1,A2,B2;
    cin >> T1>>T2>>A1>>A2>>B1>>B2;

    ll dis1 = T1*(A1-B1);
    ll dis2 = (ll)-1*T2*(A2-B2);
    if(dis1 == dis2){
        cout<<"infinity"<<endl;
        return 0;
    }
    if(dis1>0 && dis2<0){
        cout<<0<<endl;
        return 0;
    }
    if(dis1<0 && dis2>0){
        cout<<0<<endl;
        return 0;
    }

    dis1 = abs(dis1);
    dis2 = abs(dis2);

    if(dis1>dis2){
        cout<<0<<endl;
        return 0;
    }

    ll diff = max(dis1,dis2) - min(dis1,dis2);
    ll result = (ll)2 * (max(dis1,dis2)/diff);
    result--;
  
  	if(max(dis1,dis2)%diff==0){
      result--;
    }

    cout<<result<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef pair <int,int> pii;
#define FST first
#define SEC second

int w,h;
int dd[8]={0,1,0,-1,0};

void bfs(char map[50][50]){
  stack <pii> q;
  int bc=0,wc=0;
  rep(i,h){
    rep(j,w){
      if(map[j][i]=='.'){
	q.push(pii(j,i));
	int count=0;
	pii state=pii(0,0);
	while(!q.empty()){
	  int cx=q.top().FST,cy=q.top().SEC;
	  q.pop();
	  if(map[cx][cy]=='.')
	    count++;
	  map[cx][cy]='#';
	  rep(r,4){
	    int nx=cx+dd[r],ny=cy+dd[r+1];
	    if(nx<0 || ny<0 || nx>=w || ny>=h || map[nx][ny]=='#')
	      continue;
	    if(map[nx][ny]=='B'){
	      state.FST=1;
	      continue;
	    }
	    if(map[nx][ny]=='W'){
	      state.SEC=1;
	      continue;
	    }
	    q.push(pii(nx,ny));
	  }
	}
	if(state==pii(1,0))
	  bc+=count;
	if(state==pii(0,1))
	  wc+=count;
      } 
    }
  }
  printf("%d %d\n",bc,wc);
}

int main(){
  for(;;){
    cin >> w >> h;
    if(!(w+h)) break;
    char map[50][50];
    rep(i,h){
      rep(j,w){
        cin >> map[j][i];
      }
    }
    bfs(map);
  }
  return 0;
}

Measured memory_bytes: 1220
#Hが2のn乗で挟まれるかを考える
#2^n <= H <= 2^(n+1)
H = int(input())
#10^12 = 2^12 * 5^12 < 2^12 * 8*12 = 2*48
for i in range(49):
    if 2**i <= H and H<2**(i+1):
        n = i
        break

ans = 2**(n+1)-1
print(ans)

Measured memory_bytes: 2940
# ARC084C - Snuke Festival
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right

def main():
    n = int(input())
    A, B, C = [sorted(map(int, input().rstrip().split())) for _ in range(3)]
    l, ans = len(C), 0
    for i in B:
        ans += bisect_left(A, i) * (l - bisect_right(C, i))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22720