akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n,nr=0,x;
	vector<int> v;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());

	for (int i = n - 1;i > 0;i--) {
		int p = 0, r = i - 1;
		while (p < r) {
			if (v[p] + v[r] > v[i]) {
				nr = nr + r - p;
				r--;
			}
			else
				p++;
		}
	}
	cout << nr;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

const N = 105
const K = 1e5+5
var a [N]int
var T [K]int

func main() {
  var n, k int
  fmt.Scanf("%d %d", &n, &k)
  for i := 0; i < n; i++ {
    fmt.Scanf("%d", &a[i])
  }
  for i := 0; i <= k; i++ {
    T[i] = 0
  }
  for i := 0; i <= k; i++ {
    for j := 0; j < n && a[j] <= i; j++ {
      T[i] |= 1 - T[i-a[j]]
    }
  }
  if T[k] == 0 {
    fmt.Println("Second")
  } else {
    fmt.Println("First")
  }
}

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

int main()
{
 string s;
  cin >> s;
  
  for (int i = 0;i < 4; i++)
    cout << s[i];
  cout << " ";
  for (int i = 4;i < s.length();i++)
    cout << s[i];
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define ll long long
using namespace std;

int main(){
	string S,T;
	cin >>S>>T;
	int length=S.size();
	vector<int> vS(26,-1);
	vector<int> vT(26,-1);
	for(int i=0;i<length;i++){
		if(vS[S[i]-'a']==-1){
			vS[S[i]-'a']=T[i]-'a';
		}else if(vS[S[i]-'a']!=T[i]-'a'){
			cout <<"No"<<endl;
			return 0;
		}
		if(vT[T[i]-'a']==-1){
			vT[T[i]-'a']=S[i]-'a';
		}else if(vT[T[i]-'a']!=S[i]-'a'){
			cout <<"No"<<endl;
			return 0;
		}
	}
	cout <<"Yes"<<endl;

	return 0;
}

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

int table[33][100010];

int main(){
	int N,C;
	cin>>N>>C;
	for(int i=0;i<N;i++){
		int s,t,c;
		cin>>s>>t>>c;
		s--;
		c--;
		for(int j=s;j<t;j++){
			table[c][j]=1;
		}
	}
	int ans=0;
	for(int i=0;i<=100000;i++){
		int sum=0;
		for(int j=0;j<30;j++){
			sum+=table[j][i];
		}
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if((s.front() == s.back()) ^ (s.size() % 2 == 1)){
        cout << "First\n";
    }else{
        cout << "Second\n";
    }
    return 0;
}

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

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;


const int PADDING = 1000000001;
const int SIZE = 5002;
int n, m;
II P[SIZE];
int SX[SIZE], SY[SIZE];
int SXC, SYC;
short CNT[SIZE][SIZE], DP[SIZE][SIZE];

void init() {
    memset( DP, 0, sizeof(DP) );
    memset( CNT, 0, sizeof(CNT) );
    SXC = SYC = 0;
    for ( int i = 0; i < n; ++ i ) {
        SX[SXC++] = P[i].first;
        SY[SYC++] = P[i].second;
    }
    sort( SX, SX+n );
    sort( SY, SY+n );
    SXC = unique( SX, SX+n ) - SX;
    SYC = unique( SY, SY+n ) - SY;
    for ( int i = 0; i < n; ++ i ) {
        int a = lower_bound( SX, SX+SXC, P[i].first ) - SX;
        int b = lower_bound( SY, SY+SYC, P[i].second ) - SY;
        CNT[a][b] ++;
    }
}

bool input() {
    if ( ! ( cin >> n >> m ) ) return false;
    for ( int i = 0; i < n; ++ i ) {
        scanf( "%d%d", &P[i].first, &P[i].second );
    }
    return true;
}

int calc( II p ) {
    int *sxp = upper_bound( SX, SX+SXC, p.first );
    int *syp = upper_bound( SY, SY+SYC, p.second );
    int a = sxp - SX;
    int b = syp - SY;
    return DP[a][b];
}

int solve( II p1, II p2 ) {
    II A( p1.first-1, p2.second ), B = p2, C( p1.first-1, p1.second-1 ), D( p2.first, p1.second-1 );
    return calc(B) - calc(A) - calc(D) + calc(C);
}

void solve_host() {
    for ( int i = 1; i <= SXC; ++ i ) {
        for ( int j = 1; j <= SYC; ++ j ) {
            DP[i][j] = DP[i-1][j] + DP[i][j-1] - DP[i-1][j-1] + CNT[i-1][j-1];
        }
    }

    II p1, p2;
    for ( int i = 0; i < m; ++ i ) {
        scanf( "%d%d%d%d", &p1.first, &p1.second, &p2.first, &p2.second );
        printf( "%d\n", solve( p1, p2 ) );
    }
}

int main() {
    while ( input() ) {
        init();
        solve_host();
    }
    return 0;
}

Measured memory_bytes: 99064
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int a, p;
    cin >> a >> p;

    p += a * 3;

    cout << p / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

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

    vector<vector<int> > v(2, vector<int>(n));
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < n; j++)
            cin >> v[i][j];

    vector<vector<int> > dp(2, vector<int>(n));
    dp[0][0] = v[0][0];

    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < n; j++) {
            int up = 0;
            int left = 0;
            if(i > 0)
                up = dp[i - 1][j];
            if(j > 0)
                left = dp[i][j - 1];
            dp[i][j] = max(up, left) + v[i][j];
        }
    }

    cout << dp[1][n - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
juice_list = []

for _ in range(N):
    a, b = map(int, input().split())
    juice_list.append((a, b))

juice_list.sort(key=lambda x: x[0])

juice_num = 0
money = 0
for juice in juice_list:
    if juice_num + juice[1] < M:
        money += juice[0] * juice[1]
        juice_num += juice[1]
    else:
        money += (M - juice_num) * juice[0]
        juice_num += M - juice_num
        break

print(money)


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

int main(){
	int k;
	while(cin >> k,k){
		int sum = 0;
		for(int i = 0; i < k*(k-1)/2; i++){
			int a;
			cin >> a;
			sum += a;
		}
		cout << sum/(k-1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     db(i)               cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int s,w; cin>>s>>w;
    if(s>w) cout<<"safe\n";
    else cout<<"unsafe\n";
}

signed main() { 
    IO();
    // #ifndef ONLINE_JUDGE
    // freopen(input, "r", stdin);
    // freopen(output, "w", stdout);
    // freopen(error, "w", stderr);
    // #endif
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}

ll n,m,k;
char a[10][10];

void solve(){

    cin >> n >> m >> k;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin >> a[i][j];
        }
    }

    ll m1=0,m2=0;
    ll ans=0;
    for(;m1<(1<<n);m1++){
        m2=0;
        for(;m2<(1<<m);m2++){
            ll c=0;
            for(ll i=0;i<n;i++){
                if( (m1>>i)&1 )
                    continue;
                for(ll j=0;j<m;j++){
                    if((m2>>j)&1)
                        continue;
                    if(a[i][j] == '#')
                        c++;
                }
            }
            if(c == k){
                ans++;
            }
        }
    }

    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 200100;

int P[65][MAX_N];   // 10**18 == 2*60だから

int main()
{
    ll N, K; cin >> N >> K;
    int A[N];
    rep(i,N){
        cin >> A[i];
        A[i]--;
    }
    rep(i,65){
        if(i == 0){
            rep(j,N) P[i][j] = A[j];
        }else{
            rep(j,N) P[i][j] = P[i-1][P[i-1][j]];
        }
    }
    bitset<65> Kbit(K);
    int cur = 0;
    for(int i=64; i>=0; i--){
        if(Kbit.test(i)){
            cur = P[i][cur];
        }
    }
    cur++;
    cout << cur << endl;
}

Measured memory_bytes: 55180
//  ABC079 C - Train Ticket
//  

package main

import (
    "fmt"
    "strings"
    "strconv"
    "os"
)

var Pat [][]string

func factorial(i int) int {

    if i == 0 {
        return 1
    }

    return 2*factorial(i-1)
}


func calfunc(Q []string,pPat []string) {
    var res int = 0
    var tmp int

    res,_ = strconv.Atoi(Q[0])
    for i := 0; i < len(pPat); i++ {
        if pPat[i] == "+" { 
            tmp,_ = strconv.Atoi(Q[i+1])
           res += tmp
           //fmt.Println("n=",n)

        } else if pPat[i] == "-" {   // false 
            tmp,_ = strconv.Atoi(Q[i+1])
           res -= tmp
        }
    }
    
    //fmt.Println("n=",n)
    //fmt.Println("res=",res)
    if res == 7 {
        for i := 0; i < len(pPat); i++ { 
            fmt.Print(Q[i])
            fmt.Print(pPat[i])
        }
        fmt.Print(Q[len(pPat)])
        fmt.Println("=7")
        os.Exit(0)
    }
    return 
}


func main() {
    var In string
    var N []string
//    var Sum int = 0
    var digit int
    var mask uint =1

    fmt.Scan(&In)
    slice := strings.Split(In,"")

    if len(slice) != 4 {
        fmt.Println("usage:ABCD")
        os.Exit(0)
    }


    N = make([]string,4)
    N = slice

    //fmt.Println(N)

    digit = factorial(len(N)-1)
    //fmt.Println("digit=",digit)

    Pat = make([][]string,digit)
    for i :=0; i < digit; i++ {
        Pat[i] = make([]string,len(N)-1)
    }

    
    for i:= 0; i < digit; i++ {
        k := uint(i)
        //fmt.Printf("%b\n",i)
        for j := 0; j < len(N)-1; j++ {
            if k&mask == 1 {
                Pat[i][j] = "+"
            } else {
                Pat[i][j] = "-"
            }
            //fmt.Printf("%8b\n",k&mask)
            k=k>>1
        }
    }

    for i:=0; i < digit;i++ {
        //fmt.Println(Pat[i])
        calfunc(N,Pat[i])
    }

}



Measured memory_bytes: 640
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W=MI()
    a=[[] for _ in range(H+2)]
    a[0]="#"*(W+2)
    for i in range(H):
        a[i+1]="#"+input()+"#"
        
    a[-1]="#"*(W+2)
    
    for i in range(H+2):
        print(a[i])

main()


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

using namespace std;

long long MOD = 1000000007;

int main()
{
    string str;
    cin >> str;

    vector<vector<long long>> dp(str.size(), vector<long long>(13, 0));

    if (str[0] == '?')
    {
        for (int i = 0; i < 10; i++)
        {
            dp[0][i] = 1;
        }
    }
    else
    {
        int t = str[0] - '0';
        dp[0][t] = 1;
    }

    for (int i = 1; i < str.size(); i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (str[i] == '?')
            {
                if (dp[i - 1][j] != 0)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        int num = ((j * 10) + k) % 13;
                        dp[i][num] += dp[i - 1][j];
                        if (dp[i][num] > MOD)
                        {
                            dp[i][num] %= MOD;
                        }
                    }
                }
            }
            else
            {
                if (dp[i - 1][j] != 0)
                {
                    int t = str[i] - '0';
                    int num = ((j * 10) + t) % 13;
                    dp[i][num] += dp[i - 1][j];
                    if (dp[i][num] > MOD)
                    {
                        dp[i][num] %= MOD;
                    }
                }
            }
        }
    }

    cout << dp[str.size() - 1][5];

    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  string s; cin >> s;
  int n = s.size();
  vector<int> ans(n);

  for (int i=0, cnt=0; i<n; i++) {
    if (s[i] == 'R') { cnt++; continue; }
    if (cnt == 0) continue;

    ans[i] += cnt / 2;
    ans[i-1] += cnt - cnt/2;
    cnt = 0;
  }

  for (int i=n-1, cnt=0; i>=0; i--) {
    if (s[i] == 'L') { cnt++; continue; }
    if (cnt == 0) continue;

    ans[i] += cnt / 2;
    ans[i+1] += cnt - cnt/2;
    cnt = 0;
  }

  REP(i,n) cout << ans[i] << " ";
  return 0;
}


Measured memory_bytes: 3880
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n;
string s;

int main(){
	cin >> n;
	cin >> s;
	
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R') cnt++;
	}
	
	if(cnt <= n - cnt){
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    double N, T, A, h;
    double diff = 100000000;
    int ans;
    cin >> N >> T >> A;
    rep(0, i, N)
    {
        cin >> h;
        if (fabs((T - h * 0.006) - A) < diff)
        {
            ans = i + 1;
            diff = fabs((T - h * 0.006) - A);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
  N = int(input())
  H = [int(i) for i in input().split()]
  dp = [float('inf')] * N
  dp[0] = 0
  dp[1] = abs(H[0] - H[1])

  for i in range(2, N):
    dp[i] = min(dp[i - 2] + abs(H[i - 2] - H[i]), dp[i - 1] + abs(H[i - 1] - H[i]))

  return dp[N - 1]

print(solve())



Measured memory_bytes: 13976
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

int n,a,b,c;
vector<int>l;
const int infty=1e9;

int rec(int num,int A,int B,int C){
  if(num==n)return (A!=0&&B!=0&&C!=0)?abs(A-a)+abs(B-b)+abs(C-c):infty;
  int x=rec(num+1,A+l[num],B,C)+10*(A!=0);
  int y=rec(num+1,A,B+l[num],C)+10*(B!=0);
  int z=rec(num+1,A,B,C+l[num])+10*(C!=0);
  int a=rec(num+1,A,B,C);
  return min({x,y,z,a});
}
void solve(){
  cin>>n>>a>>b>>c;
  l.resize(n);
  rep(i,n)cin>>l[i];
  int ans=rec(0,0,0,0);
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f,g,h,j,i;
 int k,sum=0,tc;
 
    string s,s1;
    cin>>s>>s1;
    map<char, int> m, m1;
    string ans = "Yes";
    for( i=0; i<s.size(); i++)
    {
        m[s[i]]++;
        m1[s1[i]]++;
        if(m[s[i]] != m1[s1[i]])
        {
            ans = "No";
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 776
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <stack>
#include <string>

bool is_paren(int c) {
  return (c == '(' || c == ')' || c == '[' || c == ']');
}

bool is_openparen(int c) {
  return (c == '(' || c == '[');
}

char to_closeparen(int c) {
  if (c == '(') return ')';
  if (c == '[') return ']';
  assert(false);
}

int testcase_ends() {
  char buf[128];
  fgets(buf, sizeof buf, stdin);
  std::string s = buf;
  if (s.back() == '\n') s.pop_back();
  if (s == ".") return 1;

  std::stack<char> st;
  for (auto c: s) {
    if (!is_paren(c)) continue;
    if (is_openparen(c)) {
      st.push(to_closeparen(c));
    } else {
      if (st.empty() || st.top() != c) return puts("no"), 0;
      st.pop();
    }
  }
  puts(st.empty()? "yes": "no");
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2564
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    ll m; cin>>m;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    ll LCM = (a[0] / 2);
    for(int i=1; i<n; i++){
        LCM = (LCM / __gcd(LCM, (a[i] / 2)) * (a[i] / 2));
        if(m < LCM){
            cout << 0 << endl;
            return 0;
        }
    }

    for(int i=0; i<n; i++){
        ll div = LCM / (a[i] / 2);
        if(div % 2 != 1){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (m / LCM - m / (2 * LCM)) << endl;

    return 0;
}

Measured memory_bytes: 1024
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let _n: i32 = read();
    let s = read::<String>().as_bytes().to_vec();

    let ans = s.windows(2).filter(|cc| cc[0] != cc[1]).count();

    println!("{}", ans + 1);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4476
#include<stdio.h>

int main(void) {

	int height = 0;	scanf("%d", &height);
	int width = 0;	scanf("%d", &width);

	while (1) {

		if ((height == 0) && (width == 0)) {
			break;
		}
		else {
			
			for (int i = 0; i < height; i++) {

				for (int j = 0; j < width; j++) {

					if ((i == 0) || (i + 1 == height) || (j == 0) || (j + 1 == width)) {
						printf("#");
					}
					else {
						printf(".");
					}

				}
				printf("\n");
			}
			printf("\n");

			scanf("%d %d", &height, &width);
		}
	}
	return 0;
}


Measured memory_bytes: 2036
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

x=int(input())
for i in range(1,1000):
    if (i*360)%x==0:
        print((i*360)//x)
        exit()

Measured memory_bytes: 10480
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            //SolveA(args);
            SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        private const int M = 1000000007;
        private static void SolveB(string[] args)
        {
            int r = ReadAndParseInt();
            if( r < 1200)
            {
                Console.WriteLine("ABC");
            }else if( r < 2800)
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("AGC");
            }
        }
    }
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Go Home
            int x = int.Parse(Console.ReadLine());
            int i = 1;
            int distance = 0;

            while (true)
            {
                distance += i;

                if (distance >= x)
                {
                    break;
                }

                i++;
            }

            Console.WriteLine(i);
        }
    }
}

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

const int N = 4e6+5;
bitset<N> b;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int n;
    cin>>n;
    int a[n];
    for (int i=0; i<n; i++) cin>>a[i];

    int sum = 0;
    b.set(0);
    for (auto x:a){
        sum += x;
        b |= b<<x;
    }

    int mid = (sum+1)/2;

    for (;;mid++){
        if (b[mid]){
            cout<<mid<<endl;
            return 0;
        }
    }

    return 0;
}



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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

string s;

int main(){
    cin >> s;
    string ans[3];
    ans[0] = "Sunny";
    ans[1] = "Cloudy";
    ans[2] = "Rainy";
    for(int i = 0; i < 2; i++){
        if(s == ans[i]){
            cout << ans[i+1] << endl;
            return 0;
        }
    }
    cout << ans[0] << endl;
}

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

int main() {
    string stra,strb,strc;
    cin >> stra >> strb >> strc;
    int xa,xb,xc,ya,yb,yc;
    char a = stra[0];
    char b = strb[0];
    char c = strc[0];
    xa = (int)a;
    xb = (int)b;
    xc = (int)c;
    ya = xa-32;
    yb = xb-32;
    yc = xc-32;
    cout << (char)ya << (char)yb << (char)yc << endl;
}

Measured memory_bytes: 3556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		if(p[0]+p[1]>=10)
		{
			Console.WriteLine("error");
		}
		else
		{
			Console.WriteLine(p[0] + p[1]);
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main()
{
    char c;

    cin >> c;

    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        cout << "vowel";
    else
        cout << "consonant";

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
const int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while(1) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

  int count = 0;
  int max_count = 0;
  int prev_h = 0;
  rep(i,n) {
    int h;
    scanf("%d", &h);
    if (h <= prev_h) {
      count++;
      if (max_count < count) max_count = count;
    }
    else {
      count = 0;
    }
    prev_h = h;
  }

  printf("%d\n", max_count);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	long long dt[n];
	rep(i,n)cin>>dt[i];
	long long minnum=100000001;
	rep(i,n)minnum=min(minnum,dt[i]);
	loop(i,1,minnum+1){
		int cnt=0;
		rep(j,n){
			if(dt[j]%i==0)cnt++;
		}
		if(cnt==n)cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
n, m = map(int, input().split())
a = list()
for i in range(n) :   #1行ずつn行まで読み込みlistに格納
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))

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


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

int arr[26];
int main()
{
  string s;
  cin>>s;
  for(int i=0;i<26;i++) arr[i]=0;
  for(int i=0;i<s.length();i++)
  {
    arr[s[i]-'a']++;
  }
  int flag=0;
  for(int i=0;i<26;i++)
  {
    if(arr[i]==0)
    {
      flag=1;
      char a=char(i+'a');
      cout<<a<<endl;
      break;
    }
  }
  if(flag==0) cout<<"None"<<endl;
  
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int i;
            int n = Integer.parseInt(br.readLine());
            ArrayDeque<String> list = new ArrayDeque<String>();
            String[] num = new String[2];
            String command;
            char c;
            for(i=0; i<n; i++)
            {
                command = br.readLine();
                c = command.charAt(0);

                if(c == 'd')
                {
                    c = command.charAt(6);
                    if(c == 'F')
                    {
                        list.pollFirst();
                    }
                    else if(c == 'L')
                    {
                        list.pollLast();
                    }
                    else
                    {
                        num = command.split(" ",0);
                        list.remove(num[1]);
                    }
                }
                else
                {
                    num = command.split(" ",0);
                    list.offerFirst(num[1]);
                }
            }

            StringBuilder s = new StringBuilder();
            s.append(list.poll());
            while(list.size()>0)
            {
                s.append(" ").append(list.poll());
            }
            System.out.println(s);
        }
        catch(Exception e)
        {
        }
    }
}

Measured memory_bytes: 221792
N = input()
a = input().split()

a = [float(i) for i in a]#float cast
p = 1
list.sort(a)
#print("初期値"+ str(a))
N = int(N)
for j in range(N-1):
    sum = a[j]
    for i in range(1):
        sum = sum + a[p]
        ans = sum / 2
        a[p] = ans
        p += 1
    list.sort(a)
    #print(str(j) + "回目:" + str(a))

ans = sum / 2
print(ans)
    

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

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

int main() {
  vll a(3); cin >> a[0] >> a[1] >> a[2];
  int cnt = INT_MAX;
  int ans = 0;
  while (1) {
    if (cnt == 0 || a[0] % 2 == 1 || a[1] % 2 == 1 || a[2] % 2 == 1) break;
    sort(a.begin(), a.end());
    if (cnt > 5 && a[2] - a[0] <= 2) cnt = 5;
    vll b(3);
    b[0] = a[1] / 2 + a[2] / 2;
    b[1] = a[0] / 2 + a[2] / 2;
    b[2] = a[0] / 2 + a[1] / 2;
    a = b;
    cnt--;
    ans++;
  }
  if (cnt == 0) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a2 = a[::2]
a1 = a[1::2]
aone = (sum(a2) -sum(a1)) // 2
lasta = aone
print(aone * 2)
for i in range(n - 1):
    print((a[i] - lasta) * 2)
    lasta = a[i] - lasta

Measured memory_bytes: 14028
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto ans = 0ll;
	auto a = 0;
	auto b = 0;
	auto ab = 0;
	for (auto i = 0; i < N; ++i)
	{
		string s;
		cin >> s;

		for (auto i = 0; i < (int)s.length() - 1; ++i)
		{
			if (s[i] == 'A' && s[i + 1] == 'B')
			{
				++ans;
			}
		}

		if (s[0] == 'B')
		{
			if (s[s.length() - 1] == 'A')
			{
				++ab;
			}
			else
			{
				++b;
			}
		}
		else if (s[s.length() - 1] == 'A')
		{
			++a;
		}
	}

	if (ab > 0)
	{
		ans += ab - 1;
		if (a > 0)
		{
			++ans;
			--a;
		}
		if (b > 0)
		{
			++ans;
			--b;
		}
	}
	ans += min(a, b);

	cout << ans << 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 long long ll;
const int inf = 1001001001;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && a != c) cout <<"Yes"<<endl;
  else if (b == c && b != a) cout <<"Yes"<<endl;
  else if (a == c && c != b) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
  
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
def colon(a,b,h,m):
    urh = 0.5
    urm = 6
    hmr = (h * 60) * urh + m * urh
    mr = m * urm
    ay = a * math.sin(math.radians(hmr))
    ax = a * math.cos(math.radians(hmr))
    by = b * math.sin(math.radians(mr))
    bx = b * math.cos(math.radians(mr))
    #print(hmr,mr,ay,ax,by,bx)
    ans = math.sqrt((ay - by) ** 2 + (ax - bx) ** 2)
    print(ans)
    #print(ans - 4.56425719433005567605)
if __name__ == "__main__":
    a,b,h,m = map(int,input().split())
    colon(a,b,h,m)


Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int h,w;cin >> h >> w;
    vector<vector<int>> a(h,vector<int> (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> b(h,vector<int> (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> b[i][j];
        }
    }
    bool dp[h+1][w+1][162*81];
    memset(dp,false,sizeof(dp));
    queue<pair<P,int>> q;
    q.push(mp(mp(0,0),abs(a[0][0]-b[0][0])));
    while(!q.empty()){
        auto qq = q.front();q.pop();
        int x = qq.first.second, y = qq.first.first;
        int c = qq.second;
        //cout << x << " " << y << " " << c << endl;
        if(dp[y][x][c]) continue;
        dp[y][x][c] = true;
        for (int i = 0; i < 2; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if(0<=nx&&nx<w&&0<=ny&&ny<h){
                int nc = abs(c+abs(a[ny][nx] - b[ny][nx]));
                q.push(mp(mp(ny,nx),nc));
                nc = abs(c-abs(a[ny][nx] - b[ny][nx]));
                q.push(mp(mp(ny,nx),nc));
            }
        }
    }

    for (int i = 0; i < 162*81; i++) {
        if(dp[h-1][w-1][i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 113580
#include<bits/stdc++.h>
    #define ll long long
    #define rep(i,a,b) for(i=a;i<b;i++)
    #define pb push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define vi vector < ll  int >
    #define CLR(a) memset((a),0,sizeof(a))
    #define mp make_pair
    #define hell 1000000007
    using namespace std;
    ll mod=998244353;
ll pr( ll x , ll y)
{
    ll ans=1;
    if(y==0) return ans;
    while(y>1)
    {
        if(y&1) ans*=x;
        x*=x;
        y/=2;
        x%=mod;
        ans%=mod;
    }
    ans*=x;
    ans%=mod;
    return ans;
}
ll fact( ll n)
{
    ll ans=1,i;
    rep(i,1,n+1)
    {
        ans*=i;
        ans%=mod;
    }
    return ans;
}
ll in(ll x) { return  pr(x,mod-2);}

void solve()
{
 ll i,j=1,k,n,m=0,f,s1=0,x,c=1,y=0,a=0,b=0,d;
 cin>>n>>m;
 if(n%m==0) {cout<<0; return;}
 if(n>m)
 {
     n=n-(n/m)*m;
 }
 if(abs(n-m)<n) cout<<abs(n-m);
 else cout<<n;
}


 //}

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


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c = readInts()
k = I()
for i in range(k):
    if a < b < c:
        print('Yes')
        exit()

    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
    #print(a,b,c)
if a < b < c:
    print('Yes')
    exit()
else:print('No')


Measured memory_bytes: 10452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=309;

int n,m,l;
ll dis[N][N],a[N][N];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>l;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(i!=j)dis[i][j]=a[i][j]=1e18;
    for(int i=1;i<=m;i++){
        int u,v,w;cin>>u>>v>>w;
        dis[u][v]=dis[v][u]=w;
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(dis[i][j]<=l&&i!=j)a[i][j]=1;
        }
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
            }
        }
    }
    int qe;cin>>qe;
    while(qe--){
        int u,v;cin>>u>>v;
        if(a[u][v]==1e18)cout<<-1<<'\n';
        else cout<<a[u][v]-1<<'\n';
    }
    return 0;
}


Measured memory_bytes: 2048
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n, t;
int a[3001];
int b[3001];

int dpl[3002][3002];
int dpr[3002][3002];


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

	cin >> n >> t;
	rep(i,n) {
		cin >> a[i + 1] >> b[i + 1];
	}


	rep(i, n+2)rep(j, t)dpl[i][j] = dpr[i][j] = -INF;
	dpl[0][0] = 0;
	dpr[n + 1][0] = 0;

	rep(i, n) rep(j, t) {
		if(j + a[i+1] < t)dpl[i + 1][j + a[i + 1]] = max(dpl[i + 1][j + a[i + 1]], dpl[i][j] + b[i + 1]);
		dpl[i + 1][j] = max(dpl[i + 1][j], dpl[i][j]);
	}
	for (int i = n + 1;  i > 1; i--) rep(j, t) {
		if(j + a[i-1] < t) dpr[i - 1][j + a[i - 1]] = max(dpr[i - 1][j + a[i - 1]], dpr[i][j] + b[i - 1]);
		dpr[i - 1][j] = max(dpr[i - 1][j], dpr[i][j]);
	}
	int ans = 0;

	for (int i = 1; i <= n; i++) {
		int ma[3001];
		ma[0] = dpl[i - 1][0];
		rep(j, t - 1)ma[j + 1] = max(dpl[i - 1][j + 1], ma[j]);

		rep(j, t) {
			ans = max(ans, ma[t - j - 1] + dpr[i + 1][j] + b[i]);
		}
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 70784
n = int(input())
a = input().split()
pl = []
sb = []
for i in range(len(a)):
	pl.append(i+int(a[i])+1)
	if i - int(a[i]) > 0:
		sb.append(i-int(a[i])+1)


if len(sb) == 0:
	print('0')
else:

# spl = sorted(pl)
	isb = [int(i) for i in sb]
	ipl = [int(i) for i in pl]
	ssb = sorted(isb)
	t = min(ssb)
	# tl = [0] * max(ipl)
	tl = [0] * 2000000	
	for i in ssb:
		if int(i)-1 < len(tl):
			tl[int(i)-1] += 1
	# print(pl)
	# print(sb)
	# print(tl)
	cnt = 0
	for i in pl:
		if int(i)-1 < len(tl):
			cnt += tl[int(i)-1]

	print(cnt)
	



Measured memory_bytes: 59624
N, A, B = map(int, input().split())

ans = 0

sml = A
big = B

if (A-B) > 0:
    sml = B
    big = A

if (A - B) % 2 == 0:
    ans = (big - sml) // 2
else:
    s = sml - 1
    b = N - big

    if s > b:
        t = (big - sml) + (2*b) + 1
    else:
        t = (big - sml) + (2*s) + 1

    ans = t // 2

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef complex<double> cd;
const int maxn = 5e5 + 10;
const double PI = acos(-1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    for (int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for (; j & bit; bit >>= 1)
            j ^= bit;
        j ^= bit;
 
        if (i < j)
            swap(a[i], a[j]);
    }
    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }
    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}
 
vector<ll> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size()) 
        n <<= 1;
    fa.resize(n);
    fb.resize(n);
 
    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);
 
    vector<ll> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

int b[maxn], g[maxn], pw[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int p = 200003;
	int now = 1;
	for (int i = 0; i <= p-2; i++){
		g[now] = i;
		pw[i] = now;
		now = 2*now%p;
	}
	int n;
	cin >> n;
	vector<int> cnt(p-1);
	for (int i = 1; i <= n; i++){
		int x;
		cin >> x;
		if (x == 0)
			continue;
		cnt[g[x]] ++;
		b[g[x]+g[x]] ++;
	}
	ll answer = 0;
	vector<ll> a = multiply(cnt, cnt);
	for (int i = 0; i <= 2*p-2; i++)
		answer += 1LL*(a[i]-b[i])/2*pw[i%(p-1)];
	cout << answer << endl;
}


Measured memory_bytes: 28056
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main() {    
    int n,k;
    string s;
    cin >> n >> s >> k;
    for(int i = 0; i < n; i++) {
        if(s[i] != s[k-1]) cout << '*';
        else cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.begin()+3);
    cout << a[0]*a[1]/2 << endl;
}

Measured memory_bytes: 256
x,y,a,b,c=map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
pqr = []
for i in range(a):
    pqr.append([p[i],"p"])
for i in range(b):
    pqr.append([q[i],"q"])
for i in range(c):
    pqr.append([r[i],"r"])
pqr.sort(reverse=True)
cx = 0
cy = 0
cr = 0
s = 0
for e,c in pqr:
    if c =="p":
        if cx <x:
            cx+=1
            s+=e
    elif c =="q":
        if cy <y:
            cy+=1
            s+=e
    else:
        cr+=1
        s+=e
    if cx+cy+cr ==x+y:
        break
print(s)


Measured memory_bytes: 129320
// ITP1_7_D:   Matrix Multiplication
// 2017.7.27

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int a[101][101], b[101][101];
	long long c[101][101], s;
	int i, j, k;
	int n, m, l;

	scanf("%d%d%d", &n, &m, &l);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) scanf("%d", &b[i][j]);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			s = 0;
			for (k = 0; k < m; k++) {
				s += a[i][k] * b[k][j];
			}
			c[i][j] = s;
		}
	}

	for (i = 0; i < n; i++) {
		printf("%lld", c[i][0]);
		for (j = 1; j < l; j++) printf(" %lld", c[i][j]);
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 2112
//https://atcoder.jp/contests/abc063/tasks/abc063_b
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>s;
	n=s.size();
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(s[i]==s[j]){
				cout<<"no"<<endl;
				return 0;
			}
		}	
	}
	cout<<"yes"<<endl;
}



Measured memory_bytes: 256
import sys,math
a=list(map(int,sys.stdin.read().split()))
a.pop(-1)

for n in a:
  dp=[0]*35
  dp[0]=1
  for i in range(n+1):
    for j in [+1,+2,+3]:
      dp[i+j]+=dp[i]
  print(math.ceil(dp[n]/3650))


Measured memory_bytes: 5656