akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations_with_replacement

N, M, Q = map(int,input().split())
x = [_ for _ in range(1, M+1)]
y = list(combinations_with_replacement(x, N))
l = [list(map(int, input().split())) for _ in range(Q)]

ans = []
z = 0
for i in range(len(y)):
    for j in range(Q):
        if y[i][l[j][1]-1] - y[i][l[j][0]-1] == l[j][2]:
            z += l[j][3]
        ans.append(z)
    z = 0
print(max(ans))

Measured memory_bytes: 187628
//  atcodder.xcode
//  main.cpp
//  Created by conan1024hao on 2019/11/09.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリ
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;
    cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    int cnt[100001];
    memset(cnt,0,sizeof(cnt));
    bool abc=false;
    if(d[0]>0)
        abc=true;
    ll ans=1;
    for(int i=1;i<n;i++){
        cnt[d[i]]++;
        if(d[i]==0)
            abc=true;
    }
    int i=1;
    while(cnt[i+1]){
        for(int j=0;j<cnt[i+1];j++)
        {
            ans*=cnt[i];
            ans%=998244353;
        }
        i++;
    }
    bool ci=0;
    for(int i=1;i<n;i++){
        if(cnt[i]==0)
        {ci=1;continue;}
        if(cnt[i]!=0&&ci!=0)
            abc=true;
    }
    if(abc==true)
        cout<<0<<endl;
    else
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


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

	int ans = 0;
	for(int i=0;i<n;i++){
		bool ok = true;
		for(int j=i;j>=0;j--){
			if(a[i]<a[j]) ok = false;
		}
		if(ok) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import combinations as comb


def main():
    abc = list(map(int, input().split()))
    abc_pairs = comb(abc, 2)
    ans = float("inf")

    for abc_pair in abc_pairs:
        ans = min(ans, sum(abc_pair))

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
def main():
    N=int(input())
    s=input()
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]
    for i in range(len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if s.find(str(k),f+1,l)!=-1: ans+=1
                    

    print(ans)
     
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    string s;
    cin >> s;
    string k;
    rep(i, s.size()){
        k += 'x';
    }
    cout << k << endl;
}



Measured memory_bytes: 256
import java.util.*;


	public class Main {
	public static void main( String[] args) {			
					
					Scanner in = new Scanner(System.in);
					long a = in.nextLong();
					
					long b = a%500;
					long c = a/500;
					long h = b%5;
					long g = b/5;
					
					System.out.println(c*1000+ g*5);
					
			}}

Measured memory_bytes: 22868
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>0)cout<<"Positive"<<endl;
    else if(a<=0&&b>=0)cout<<"Zero"<<endl;
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    while(true){
        int a,b;
        cin >> a >> b;
        if(a+b == 0) break;
        cout << min(a,b) << ' ' << max(a,b) << endl;
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int l = (B - A) * (B - A - 1) / 2;
		Console.WriteLine(l - A);
		
		
	}
	int A,B;
	public Sol(){
		var d = ria();
		A = d[0]; B = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}



int main(){
    int n;
    cin >> n;
    int b[n-1];
    rep(i,n-1) cin >> b[i];

    int a[n];
    int ans=0;
    
    a[0]=b[0];
    ans=a[0];
    for(int i=1;i<n-1;i++){
        a[i]=min(b[i-1],b[i]);
        ans+=a[i];
    }
    a[n-1]=b[n-2];
    ans+=a[n-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int N; long long ans;
char c[10]; map<char, long long> m;
char I[5] = {'M', 'A', 'R', 'C', 'H'};
int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    cin >> c; m[c[0]]++;
  }
  for(int i = 0; i < 3; i++) {
    for(int j = i+1; j < 4; j++) {
      for(int k = j+1; k < 5; k++) {
        ans += m[I[i]]*m[I[j]]*m[I[k]];
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;    
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int r=sc.nextInt();
		System.out.println(2*r*Math.PI);
		sc.close();
	}


}


Measured memory_bytes: 35924
# coding: utf-8
import math
import numpy
N = int(input())
#a, b = map(int,input().split())
#A = list(map(int,input().split()))

if 400<=N<600:
    print(8)
elif 600<=N<800:
    print(7)
elif 800<=N<1000:
    print(6)
elif 1000<=N<1200:
    print(5)
elif 1200<=N<1400:
    print(4)
elif 1400<=N<1600:
    print(3)
elif 1600<=N<1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 27152
//https://atcoder.jp/contests/dp/tasks/dp_d
#include <bits/stdc++.h>

#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)

#define endl "\n"
#define ll long long int

using namespace std;

int main()
{
    fastio;
    ll n;
    cin>>n;
    ll weight;
    cin>>weight;
    ll w[n];
    ll v[n];
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][weight+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=weight;j++){
            if(w[i-1]<=j){
                dp[i][j]=v[i-1]+dp[i-1][j-w[i-1]];
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    cout<<dp[n][weight];
    return 0;
}

Measured memory_bytes: 82564
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(LL N, LL M, LL Q, vector<LL> L, vector<LL> R, vector<LL> p, vector<LL> q){
	VVI cell;
	cell.resize(N + 1);
	FOR(i, 1, N + 1) {
		cell[i].resize(N + 1);
	}

	REP(m, M) {
		for (int i = 1; i <= L[m]; i++) {
			for (int j = R[m]; j < N + 1; j++) {
				cell[i][j]++;
			}
		}
	}

	REP(i, Q) {
		cout << cell[p[i]][q[i]] << endl;
	}
}


int main(){	
	LL N;
	LL M;
	LL Q;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<LL> R(M-1+1);
	vector<LL> L(M-1+1);
	scanf("%lld",&Q);
	vector<LL> p(Q-1+1);
	vector<LL> q(Q-1+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&L[i]);
		scanf("%lld",&R[i]);
	}
	for(int i = 0 ; i <= Q-1 ; i++){
		scanf("%lld",&p[i]);
		scanf("%lld",&q[i]);
	}
	solve(N, M, Q, L, R, p, q);
	return 0;
}



Measured memory_bytes: 11264
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  string s;
  cin >> s;

  s[3] = '8';

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 5;
int main(){
	int n,k=2;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	vector<int> dp(n,INF);
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
		if(i-k<=0){
			dp[i]=abs(v[i]-v[0]);}
		else{
			for(int j=1;j<=k;j++){
				//if(j==2)  cout<<dp[i-j]+abs(v[i]-v[i-j])<<endl;
				dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
					//cout<<dp[i]<<"  "<<j<<endl;
					}
			}
		}
		//for(int x: dp)
			//cout<<x<<"\t";
		cout<<dp[n-1]<<endl;
		


}
	

Measured memory_bytes: 1024
#include<iostream>                                              
#include<string>                                                
#include<algorithm>                                             
using namespace std;                                            
                                                                
int main(void) {                                                
  string str, command, p;                                       
  int i, n, a, b;                                               
  cin >> str >> n;                                              
  for (i=0; i<n; i++) {                                         
    cin >> command >> a >> b;                                   
    if (command=="replace") {                                   
      cin >> p;                                                 
      str.replace(a,b-a+1,p);                                   
    } else if (command=="reverse") {                            
      p = str.substr(a,b-a+1);                                  
      reverse(p.begin(),p.end());                               
      str.replace(a,b-a+1,p);                                   
    } else if (command=="print") {                              
      cout << str.substr(a,b-a+1) << endl;                      
    }                                                           
  }                                                             
  return 0;                                                     
}                              

Measured memory_bytes: 3180
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
		// 文字列の入力
		
		System.out.println(b / c - (a - 1) / c);
		
		
	}
}

Measured memory_bytes: 35608
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
//    static HashMap<Integer,Integer> hm;
    static int[][] dp;
    public static void main(String[] args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine().trim());
        int[][] a=new int[n][3];
        for(int i=0;i<n;i++){
            String[] s=br.readLine().split(" ");
            for(int j=0;j<3;j++){
                a[i][j]=Integer.parseInt(s[j].trim());
            }
        }

        dp=new int[n+1][3];
        for(int i=0;i<=n;i++) {
            Arrays.fill(dp[i], -1);
        }

        int res=0;
        for(int i=0;i<3;i++){
            int r=a[0][i]+algo(a,i,1);
//            System.out.println(r+" "+i);
            res=Math.max(r,res);
        }
        System.out.println(res);
    }



    public static int algo(int[][] a,int j,int n){

        if(dp[n][j]!=-1){
            return dp[n][j];
        }
        if(n>=a.length){
            return 0;
        }
        int res=0;
//        dp[n]=0;
        for(int i=0;i<3;i++)
        {
            if(i!=j) {
                int r = a[n][i] ;
                if(n+1<a.length){
                   r=r + algo(a, i, n + 1);
                }
                res = Math.max(r, res);

            }
        }
        dp[n][j]=res;
        return res;
    }


}


Measured memory_bytes: 71140
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<deque>


using namespace std;
using ll = long long;

int n;
int l[2005];
vector<int>V;

int main(){
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> l[i];
    V.push_back(l[i]);
  }
  sort(V.begin(), V.end());
  int ans = 0;
  for(int i = 0; i < n; ++i){
    //int tmp = V[i] * 2;
    for(int j = i + 2; j < n; ++j){
      int tmp = j - 1;
      while(tmp > i){
        if(V[j] >= V[i] + V[tmp]){
          break;
        }else{
          ans++;
          tmp--;
        }
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
  int N, M;
  while(cin >> N, N){
    int plane[21][21] = {{0}};
    int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
    int X = 10, Y = 10, get = 0;
    for(int i = 0; i < N; i++){
      int x, y;
      cin >> x >> y;
      plane[x][y] = 1;
    }
    cin >> M;
    while(M--){
      char d; int l, D;
      cin >> d >> l;
      switch(d){
      case 'N': D = 0; break;
      case 'E': D = 1; break;
      case 'S': D = 2; break;
      case 'W': D = 3; break;
      }
      for(int i = 0; i < l; i++){
	X += dx[D], Y += dy[D];
	get += plane[X][Y]; 
	plane[X][Y] = 0;
      }
    }
    cout << (get == N ? "Yes":"No") << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	string s;
	cin>>s;
	rep(i,s.size()){
		cout<<s[i];
		if(i==3)cout<<" ";
	}
	cout<<endl;
	return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<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 ll 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;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    auto b = a;
    sort(b.begin(), b.end());

    for(int i=0; i<n; i++){
        if(a[i] == b[n-1]) cout << b[n-2] << endl;
        else cout << b[n-1] << endl;
    }
}

Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<cstring>

#define vti vector<int>
#define forn(i,a,n) for(int i=(a);i<(n);i++)
#define ford(i,a,d) for(int i=(a);i>(d);i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define mkp(a,b) make_pair(a,b)
using namespace std;
const long long N=2e5+3;
const long long inf=0x3f3f3f3f;
typedef long long ll;

int a[N];

int main()
{
//    ios::sync_with_stdio(false);
//    freopen("a.in","r",stdin);
//    freopen("ao","w",stdout);

    int n,k;
    cin>>n>>k;
    forn(i,0,n) cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    forn(i,0,n-k) ans+=a[i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
S = input()
T = input()
c = 0
idx = 0
ans = []
for i, s in enumerate(S):
    if s == T[0] or s == '?':
        tmp = S[i:min(i+len(T), len(S))]
        flg = True
        if len(T) != len(tmp):
            continue
        for j, c in enumerate(tmp):
            if c != T[j] and c != '?':
                flg = False
                break
        if flg:
            ans.append((S[:i] + T + S[i+len(T):]).replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

Measured memory_bytes: 3064
using System;

class Program {
  static void Main(string[] args) {
    int N = int.Parse(Console.ReadLine());
    int K = int.Parse(Console.ReadLine());
    int X = int.Parse(Console.ReadLine());
    int Y = int.Parse(Console.ReadLine());
    int res = N <= K ? N * X : K * X + (N - K) * Y;
    Console.WriteLine(res);
  }
}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main(){
    int f[3];
    cin >> f[0] >> f[1] >>f[2];

    int minSum = 10000;
    minSum = min(minSum, f[0]+f[1]);
    minSum = min(minSum, f[0]+f[2]);
    minSum = min(minSum, f[1]+f[2]);

    cout << minSum << endl;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
sortedA = sorted(set(A))
ans = []
for v in sortedA:
    C = [[]]
    for i, t in enumerate(A):
        if t < v  and len(C[-1]) > 0 :
            C.append([])
        if t >= v :
            C[-1].append(t)
    tmp = []
    for t in C:
        if len(t) >= K:
            tmp += sorted(t)[:len(t)-K+1]
    tmp.sort()
    if len(tmp) >= Q:
        ans.append(tmp[Q-1] - v)
print(min(ans))

Measured memory_bytes: 3316
#include <iostream>
#include <string>

using namespace std;

string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

    int m = x.size();
    for (int i = 0; i < m; i ++ )
    {
        x[i] = x[i] + n;
        if(x[i] > 'Z') x[i] -= 26;
    }

    cout << x << endl;

    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
#define getchar getchar_unlocked
template <class T>
inline void _read(T &x)
{
    x = 0;
    char t = getchar();
    while (!isdigit(t)) t = getchar();
    while (isdigit(t))
    {
        x = x * 10 + t - '0';
        t = getchar();
    }
}
constexpr int MAXN = 1e6 + 10, mo = 998244353;
int n, m, ans, sum, fac[MAXN], inv[MAXN];
inline int C(int n, int m)
{
    return 1ll * fac[n] * inv[m] % mo * inv[n - m] % mo;
}
int main()
{
    _read(n), _read(m);
    if (n < m)
        swap(n, m);
    ans = n;
    fac[0] = fac[1] = inv[0] = inv[1] = 1;
    for (int i = 2; i <= n + m; ++i)
        fac[i] = 1ll * fac[i - 1] * i % mo, inv[i] = 1ll * (mo - mo / i) * inv[mo % i] % mo;
    for (int i = 2; i <= n + m; ++i)
        inv[i] = 1ll * inv[i] * inv[i - 1] % mo;
    for (int i = 1; i <= m; ++i)
        sum = (1ll * C(i << 1, i) * C(n + m - (i << 1), n - i) + sum) % mo;
    printf("%d", (1ll * sum * inv[2] % mo * inv[n + m] % mo * fac[n] % mo * fac[m] + ans) % mo);
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;
#define NIL NULL
  
Node root;
 
  Node treeMinimum(Node x){
  while(x->left != NIL){
  x=x->right;
  }
  return x;
  }
    
  Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key){
  return u;
  }
  if(k<u->key){
  return treeSearch(u->left,k);
  } else {
  return treeSearch(u->right,k);
  }
  }
    
  Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
  return treeMinimum(x->right);
  }
  y=x->parent;
  while(y!=NIL && x==y->right){
  x=y;
  y=y->parent;
  }
  return y;
  }
   /*
  void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
    
    
    
  }
*/
void insert(int k){
    
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
    
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root= z;
  } else if(z->key < y->key){
    y->left = z;
  } else{
    y->right = z;
  }
}
  
void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){ 
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}
  
  
int main(){
  int n, i, x;
  char com[20];
  Node z;
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
    Node t = treeSearch(root, x);
       if ( t != NIL ) printf("yes\n");
       else printf("no\n");
    } else if ( com[0] == 'i' ){
    scanf("%d", &x);   
    insert(x);
      } else if ( com[0] == 'p' ){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
      } else if ( com[0] == 'd' ){
    scanf("%d", &x);
    //treeDelete(treeSearch(root, x));
      }
  }
    
  return 0;
}

Measured memory_bytes: 19364
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

D = defaultdict(int)
for a in A:
    for i in range(61):
        D[1 << i] += bool(a & (1 << i))

ans = 0
for key, value in D.items():
    ans += key * value * (N - value)
    ans %= MOD

print(ans % MOD)


Measured memory_bytes: 122936
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
string s; cin >> s;
int n = s.size();
string ans = "No";
for(int i = 0; i < n-1; ++i){
    if(s[i]=='A' && s[i+1]=='C')ans = "Yes";
}
cout << ans << endl;
}


Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = [0] * D
for i in range(D):
    r=((i+1)%26)+1
    t[i] = r

    
M=22
day=[1,4,5,3,4,6,7,8,9,2,45,123,6,3,4,6,1,57,5,45,6,7]
q=[7,11,4,6,17,3,4,6,2,3,4,6,7,3,2,2,1,6,7,7,4,10]
    
m=[0]*D

a=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
    i=t[u]
    for y in range(u,D):
        a[y][i-1]=u+1
    if u==0:
        m[u]=s[u][i-1]
    else:
        m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d  in range(D):
    for i in range(26):
        mm[d]+=c[i]*(d+1-a[d][i])
    if not d==0:
        mm[d]+=mm[d-1]
for d in range(D):
    m[d]-=mm[d]
mmm=m[D-1]



for p in range(M):
    new_type=q[p]
    old_type=t[day[p]-1]
    #print(new_type,old_type)
    A=0
    B=0
    C=0
    #C=s[day[p]-1][old_type-1]-s[day[p]-1][new_type-1]
    for d in range(D):
        A+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    xday=day[p]
    if xday>1:
        before_new=a[xday-2][new_type-1]
        before_old=a[xday-2][old_type-1]
        now_new=a[day[p]-1][new_type-1]
        now_old=a[day[p]-1][old_type-1]
        for d in range(day[p]-1,D):
            if a[d][new_type-1]==now_new:
                a[d][new_type-1]=xday
            if a[d][old_type-1]==now_old:
                a[d][old_type-1]=before_old
    else:
        for d in range(day[p]-1,D):
            if a[d][old_type-1]==1:
                a[d][old_type-1]=0
            if a[d][new_type-1]==0:
                a[d][new_type-1]=1   
    t[day[p]-1]=new_type
    for d in range(D):
        B+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    s=mmm-(B-A+C)
    if s>mmm:
        mmm=s
    #print(mmm)
for i in range(len(t)):
    print(t[i])

Measured memory_bytes: 75144
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int x;
    cin>>x;
    for(int a=-10000;a<=10000;a++){
        for(int b=-1000;b<=0;b++){
            if(pow(a,5)-pow(b,5)==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4128
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List

def sort123(DD):
    D = [DD]
    for i in range(0, 3):
        D.append(north(D[i]))
        D.append(south(west(D[0])))
        D.append(south(east(D[0])))
    for i in range(6):
        for j in range(3):
            if j == 0:
                D.append(east(D[i + j]))
            else:
                D.append(east(D[5 + 3 * i + j]))
    D.sort()
    return D[0]

n = int(input())
dice = []
for i in range(n):
    dice.append(sort123(list(map(int, input().split()))))
key = 0
for i in range(0, len(dice)):
    if key == 1: break
    for j in range(i + 1, len(dice)):
        if dice[i] == dice[j]:
            print('No')
            key = 1
            break
if key == 0:
    print('Yes')


Measured memory_bytes: 5620
S = list(input())

if ((S[0] == S[1] and S[2] == S[3] and S[1] != S[2]) or
    (S[0] == S[2] and S[1] == S[3] and S[1] != S[2]) or
    (S[0] == S[3] and S[1] == S[2] and S[0] != S[1])):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  REP(i,n)cin>>a[i];
  /*ll x[n];
  REP(i,n){
    x[i]=0;
    REP(j,n){
      int k=(i+j)%n;
      x[i]+=(j%2==0?a[k]:-a[k]);
    }
  }*/
  ll x[n];
  x[0]=0;
  REP(i,n){
    x[0]+=(i%2==0?a[i]:-a[i]);
  }
  FOR(i,1,n){
    x[i]=-x[i-1]+2*a[i-1];
  }
  for(int i=0;i<n;i++){
    cout<<x[i]<<" ";
  }
  
  return 0;
}

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

int main() {
  int N,L;
  cin >> N >> L;
  int count = 1000;
  int ans = 0;
  for (int i = L; i < L + N; i++) {
    ans += i;
    if (abs(i) < abs(count))
      count = i;
  }
  cout << ans - count << endl;
}



Measured memory_bytes: 3644
/**
*    author:  yuya1234
*    created: 07.07.2020 10:22:53
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    int h,w,k;
    cin>>h>>w>>k;

    vector<string> v;
    string tmp;
    REP(i,h)
    {
        cin>>tmp;
        v.emplace_back(tmp);
    }

    int ans=0;
    for(int bith=0;bith<(1<<h);bith++)
    for(int bitw=0;bitw<(1<<w);bitw++)
    {
        int cnt=0;
        REP(i,h)REP(j,w)
        {
            if(bith&(1<<i))continue;
            if(bitw&(1<<j))continue;
            if(v[i][j]=='#')cnt++;
        }
        if(cnt==k)ans++;
    }

    cout<<ans<<endl;

    return 0;
}

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

int main()
{
    int x,b,c;
    cin>>x>>b>>c;
    int a[3];
    a[0]=x;
    a[1]=b;
    a[2]=c;
    sort(a,a+3);
    int val;
    if(((a[1]-a[0])%2)==0)
    {
        val=(a[1]-a[0])/2;
        val=val+a[2]-a[1];
    }
    else
    {
        if((a[2]-a[1])%2==0)
        {
            val=(a[2]-a[1])/2;
            val=val+1;
            a[2]++;
            val=val+(a[2]-a[0])/2;
        }
        else
        {
            val=(a[2]-a[0])/2;
            val=val+1;
            a[2]++;
            val=val+(a[2]-a[1])/2;

        }
    }
    cout<<val<<endl;
}


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

//#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main() {
    int n, Q;
    cin >> n >> Q;
    
    fenwick_tree<ll> fw(n);
    rep(i,n){
        int a; cin >> a;
        fw.add(i, a);
    }
    
    while(Q--){
        int type; cin >> type;
        if(type == 0){
            int p, x;
            cin >> p >> x;
            fw.add(p, x);
        }else{
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }
}

Measured memory_bytes: 8220
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();//a
		int b=scan.nextInt();//b
		int c=scan.nextInt();//間
		double cos=Math.cos(Math.toRadians(c));//cos A
		double d=Math.sqrt(b*b+a*a-2*a*b*cos);//c
		double l=a+b+d;
		double ad=b*cos;
		double h=Math.sqrt(b*b-ad*ad);
		double S=a*h/2;
		System.out.println(S+" "+l+" "+h);
	}
}


Measured memory_bytes: 26516
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] chars = s.toCharArray();
 		int l = s.length();
 		int ans = l;
		for(int i = 1; i < l; i++) {
			if(chars[i-1]!=chars[i]) {
				ans = Math.min(ans, Math.max(i, l - i));
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 27732
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

const int MAX_T = 200005;

int main(){
    int n;
    double t[105], v[105];
    double max_v1[MAX_T], max_v2[MAX_T];
    
    cin >> n;
    rep(i, n){
        cin >> t[i];
        t[i] *= 2;
    }
    rep(i, n)t[i + 1] += t[i];
    rep(i, n){
        cin >> v[i];
    }

    max_v1[0] = max_v2[(int)t[n - 1]] = 0; 
    
    int cnt = 0;
    rep(i, t[n - 1] + 1){
        if(i == t[cnt])cnt++;
        max_v1[i + 1] = min(v[cnt], max_v1[i] + 0.5);
        
    }
    
    
    for(int i = t[n - 1];i >= 0; i--){
        if(i == t[cnt - 1])cnt--;
        max_v2[i - 1] = min(v[cnt], max_v2[i] + 0.5);
    }
    double ans = 0;
    for(int i = 0; i < t[n - 1] + 1; i++){
        ans += min(max_v1[i], max_v2[i]);
    }
    printf("%.7f\n", ans / 2);
    return 0;
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  int n; cin >> n;
  vector<lint> a(n); for(int i =0;i<n;i++) { cin >> a[i]; }

  lint ans;
  vector<lint> b(n);
  b[0] = a[0];
  for(int i =1;i<n;i++) { b[i] = b[i-1]+a[i]; }

  ans=2000000000;
  for(int i=0;i<n-1;i++) { ans = min( ans, abs( (b[n-1]-b[i])-b[i] ) ); }

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

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    int a=n-1;
   for(int i=k-a;i<=k;i++)
    {
        cout << i << " ";
    }
    for(int j=k+1; j<=k+a;j++)
    {
        cout << j << " ";
    }

    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <stack>
using namespace std;
#define MAX 300000

int main(){
	string s, str;
	stack<char> st;
	st.push('.');
	while(getline(cin, str)){
		if(str == ".")break;
		while(st.top() != '.')st.pop();
		//cout << str << str.size() << endl;
		for(int i = 0;i < str.size();i++){
			if(str[i] == '[' || str[i] == '('){
				st.push(str[i]);
			}
			if(str[i] == ']' || str[i] == ')'){
				if(st.top() == '(' && str[i] == ')')st.pop();
				else if(st.top() == '[' && str[i] == ']')st.pop();
				else {st.push(']');break;}
			}
		}
		//cout << st.top();
		if(st.top() == '.' && st.top() != ']')
		cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
const int M = 1e9 + 7;
void solve () {
  int n;
  cin >> n;
  vector<ll> v(n);
  ll ans = 0;
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int bit = 0; bit < 60; ++bit) {
    int one = 0;
    for (int j = 0; j < n; ++j) {
      one += (v[j] >> bit)&1;
    }
    ans += (1ll << bit) % M * one % M * (n - one) % M;
    ans %= M;
  }
  cout << ans << endl;
}
int main () {
  cin.tie(0), ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
  int cube[60],tetra[99];
  int n,ans,i,j;
  for(i=0;i<60;i++)cube[i]=i*i*i;
  for(j=0;j<99;j++)tetra[j]=j*(j+1)*(j+2)/6;
  while(cin>>n,n){
    ans=0;
    for(i=0;cube[i]<=n;i++)for(j=0;cube[i]+tetra[j]<=n;j++)
      ans=ans>cube[i]+tetra[j]?ans:cube[i]+tetra[j];
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int ss;
	string w;
	getline(cin,w);
		ss=size(w);
		fu(0,ss){
			if(isupper(w[i])==0&&w[i]!=' '&&w[i]!='.'){
				w[i]=toupper(w[i]);
			}
		}
	cout<<w<<endl;
}

Measured memory_bytes: 1180
from itertools import product, chain

x, y, z, k = list(map(int, input().split(" ")))
a = sorted(list(map(int, input().split(" "))))
b = sorted(list(map(int, input().split(" "))))
c = sorted(list(map(int, input().split(" "))))

apb_sorted = sorted([a + b for a, b in product(a, b)])[-k:]
ans_list = sorted(
    list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]]))
)
it = reversed(ans_list)
for _ in range(k):
    print(next(it))


Measured memory_bytes: 196628
#include<stdio.h>

int main()
{
    int a,b,c;
    int mem;
    scanf("%d %d %d",&a,&b,&c);
    
    if((1<=a)&&(a<=10000)&&(1<=b)&&(b<=10000)&&(1<=c)&&(c<=10000))
    {
        if(a>b)
        {
            mem=a;
            a=b;
            b=mem;
        }
        if(b>c)
        {
            mem=b;
            b=c;
            c=mem;
            if(a>b)
            {
                mem=a;
                a=b;
                b=mem;
            }
        }
        printf("%d %d %d\n",a,b,c);
    }
    return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n, m;
	cin >> n >> m;

	vector <pair<int, string> > sub(m);

	for(int i = 0; i < m; i++)
		cin >> sub[i].first >> sub[i].second;

	int pen = 0, corr = 0;
	map<int, int> count, wa;
	
	for(int i = 0; i < m; i++){
		if(sub[i].second == "AC"){
			if(!count[sub[i].first]){
				count[sub[i].first]++;
				corr++;
				pen += wa[sub[i].first];
				wa[sub[i].first] = 0;
			}
		}
		if(sub[i].second == "WA"){
			if(!count[sub[i].first])
				wa[sub[i].first]++;
		}
	}

	cout << corr << " " << pen <<endl;





	return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int sum = 0;
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                if (1 < i && i * i < n) {
                    sum += i + n / i;
                } else if (n != 1) {
                    sum += i;
                }
            }
        }
        if (n > sum) {
            cout << "deficient number" << endl;
        } else if (n < sum) {
            cout << "abundant number" << endl;
        } else {
            cout << "perfect number" << endl;
        }
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>
#include <map>
#include <chrono>
#include <cstdlib>
#include <ctime>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793

/*vector<ll> c;
vector<vector<ll>> s;
vector<ll>last;
vector<ll>t;
vector<bool>did;*/


int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    vector<ll> a_sum(n+1);
    vector<ll> b_sum(m+1);
    rep(cnt, 0, n) {
        cin >> a.at(cnt);
    }
    rep(cnt, 0, m) {
        cin >> b.at(cnt);
    }
    a_sum[0] = 0;
    b_sum[0] = 0;
    rep(cnt, 0, n) {
        a_sum.at(cnt+1) = a_sum.at(cnt) + a.at(cnt);
    }
    rep(cnt, 0, m) {
        b_sum.at(cnt + 1) = b_sum.at(cnt) + b.at(cnt);
    }

    ll a_read=0;
    ll b_read=0;
    ll best = 0;
    for (a_read = 0; a_read <= n;a_read++) {
        if (k >= a_sum.at(a_read)) {

        }
        else {
            break;
        }
    }
    a_read--;
    best = a_read;

    for (ll i = 1; i <= m; i++) {
        if (b_sum.at(i) > k) {
            break;
        }
        while (b_sum.at(i) + a_sum.at(a_read) > k) {
            a_read--;
            if (a_read < 0) {
                a_read = 0;
                break;
            }
        }
        best = max(best, i + a_read);
    }
    cout << best << endl;

    return 0;
}

Measured memory_bytes: 9576