akhauriyash/Code-Regression huggingface dataset:
# include<iostream>
# include<cstdio>
# include<cstring>
# include<algorithm>
# include<cmath>
# include<queue>
# define LL long long
using namespace std;
const int MAX=1e6+5; 
LL suma,sumb,n,m,ans;
char s[MAX];
int main()
{
	LL t;
	scanf("%lld%s%lld",&n,s+1,&t);
	while(t--)
	{
		LL k;
		scanf("%lld",&k);
		LL cnt=ans=suma=sumb=0;
		for(int i=1,L=1,R=1;i<=n;++i)
		  {
			if(R-L<k)
			{
				if(s[i]=='D') suma++;
				if(s[i]=='M') sumb++,cnt+=suma;
				if(s[i]=='C') ans+=cnt;
			}
			else
			{
				if(s[L]=='D') suma--,cnt-=sumb;
				if(s[L]=='M') sumb--;
				if(s[i]=='D') suma++;
				if(s[i]=='M') sumb++,cnt+=suma;
				if(s[i]=='C') ans+=cnt;
				++L;
			}
			++R;
		  }
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,even,odd;
    cin>>n;
    vector<int>e(100001,0),o(100001,0);
    for(int i=0;i<n/2;i++){cin>>even>>odd;e[even]++,o[odd]++;}
    auto m_e=max_element(e.begin(),e.end()),m_o=max_element(o.begin(),o.end());
    if(m_e-e.begin()!=m_o-o.begin())cout<<n-*m_e-*m_o<<endl;
    else{
        even=*m_e,odd=*m_o;
        *m_e=0,m_e=max_element(e.begin(),e.end());
        *m_o=0,m_o=max_element(o.begin(),o.end());
        cout<<n-max(*m_e+odd,even+*m_o)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll N, total = 0;;
    cin >> N;
    vector<ll>a(N);

    rep(i, N) {
        cin >> a[i];
        total += a[i];
    }

    ll ans = pow(10, 15), x = 0, y;
    y = total;

    rep(i, N - 1) {
        x += a[i];
        y -= a[i];
        ans = min(ans, abs(x - y));
    }

    cout << ans;

    return 0;
}


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

int main() {
    string S;
    cin >> S;
    for(int i=0; i<S.size(); ++i) {
        if(i % 2 != 0 && S[i] == 'R') {
            cout << "No" << endl;
            return 0;
        } else if(i % 2 == 0 && S[i] == 'L') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
def possible(l, a, k):
    for x in a:
        k -= math.ceil(x/l)-1
    return k>=0

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mini = 1
maxi = 10**9+7
while(mini!=maxi):
    mid = (mini+maxi)//2
    if possible(mid, a, k):
        maxi = mid
    else:
        mini = mid + 1
print(mini)


Measured memory_bytes: 31156
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    if k > a[-1]:
        print("IMPOSSIBLE")
    else:
        gcd = 0
        import fractions
        for i in range(n):
            gcd = fractions.gcd(a[i], gcd)
        for i in range(n):
            if a[i] >= k:
                if (a[i] - k) % gcd == 0:
                    print("POSSIBLE")
                    exit()
        print("IMPOSSIBLE")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 77580
import math
import itertools

n=int(input())
xylist=[list(map(int,input().split())) for _ in range(n)]

def kyori(junlist):
    sum=0
    for a in range(1,n):
        i=junlist[a-1]
        j=junlist[a]
        sum+=math.sqrt((xylist[i][0]-xylist[j][0])**2+(xylist[i][1]-xylist[j][1])**2)
    return sum

allsum=0
numlist=[i for i in range(n)]
junbanlist=[]
for v in itertools.permutations(numlist):
    junbanlist.append(list(v))

for jun in junbanlist:
    allsum+=kyori(jun)

print(allsum/math.factorial(n))


Measured memory_bytes: 10356
#include<iostream>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long llong;

llong A, B,K;

int main()
{
	cin >> A >> B >> K;
	for (int i = 0; i < K; i++)
	{
		if (i % 2 == 0)
		{
			if (A % 2 == 1) A--;
			A /= 2;
			B += A;
		}
		else
		{
			if (B % 2 == 1) B--;
			B /= 2;
			A += B;
		}
	}
	cout << A << ' ' << B;
	return 0;
}

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

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

	if (a >= b && a >= c)
	{
		cout << 10 * a + b + c << endl;
	}
	else if (b >= a && b >= c)
	{
		cout << a + 10 * b + c << endl;
	}
	else
	{
		cout << a + b + 10 * c << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int r, g;
  cin >> r >> g;
  cout << 2*g-r << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**6)

N=int(input())
P=list(map(int,input().split()))
child=[[] for i in range(N)]
for i in range(N-1):
    child[P[i]-1].append(i+1)

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

dpb=[float("inf") for i in range(N)]
dpw=[float("inf") for i in range(N)]

def dfs(v):
    for nv in child[v]:
        dfs(nv)
    if child[v]:
        subdpb=[[float("inf") for i in range(0,X[v]+1)] for j in range(len(child[v]))]
        subdpw=[[float("inf") for i in range(0,X[v]+1)] for j in range(len(child[v]))]
        for i in range(X[v]+1):
            nv=child[v][0]
            if i>=X[nv]:
                subdpb[0][i]=min(subdpb[0][i],dpb[nv])
            if i>=dpw[nv]:
                subdpb[0][i]=min(subdpb[0][i],X[nv])
        for i in range(1,len(child[v])):
            nv=child[v][i]
            for j in range(X[nv],X[v]+1):
                subdpb[i][j]=min(subdpb[i][j],subdpb[i-1][j-X[nv]]+dpb[nv])
            if dpw[nv]!=float("inf"):
                for j in range(dpw[nv],X[v]+1):
                    subdpb[i][j]=min(subdpb[i][j],subdpb[i-1][j-dpw[nv]]+X[nv])

        for i in range(X[v]+1):
            nv=child[v][0]
            if i>=X[nv]:
                subdpw[0][i]=min(subdpw[0][i],dpw[nv])
            if i>=dpb[nv]:
                subdpw[0][i]=min(subdpw[0][i],X[nv])
        for i in range(1,len(child[v])):
            nv=child[v][i]
            for j in range(X[nv],X[v]+1):
                subdpw[i][j]=min(subdpw[i][j],subdpw[i-1][j-X[nv]]+dpw[nv])
            if dpb[nv]!=float("inf"):
                for j in range(dpb[nv],X[v]+1):
                    subdpw[i][j]=min(subdpw[i][j],subdpw[i-1][j-dpb[nv]]+X[nv])

        dpb[v]=subdpb[-1][X[v]]
        dpw[v]=subdpw[-1][X[v]]

    else:
        dpb[v]=0
        dpw[v]=0

dfs(0)

if min(dpb[0],dpw[0])==float("inf"):
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Measured memory_bytes: 124764
import java.io.*;
  
public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        int x = Integer.parseInt(input);
        int h = x / 3600;
        int m = (x % 3600) / 60;
        int s = (x % 3600) % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}

Measured memory_bytes: 24220
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s,t;
int S,T;

int main(){
	cin>>s>>t;
	S=s.size();
	T=t.size();
	vi dp(T+1);
	dp[0]++;
	for(int i=0;i<S;i++){
		vi DP=dp;
		for(int j=1;j<=T;j++) if(s[i]==t[j-1]){
			(DP[j]+=dp[j-1])%=mod;
		}
		dp=DP;
	}
	cout<<dp[T]<<endl;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
        //#define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
       // #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(int a,int b)
        {
            return a>b;
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int n;
            cin>>n;
            int arr[n];
            for(int i=0;i<n;i++){
            cin>>arr[i];
            }
            int miner=INT_MAX;
            for(int i=-1000;i<=1000;i++){
            int counter=0;
            for(int l=0;l<n;l++){
            counter+=(arr[l]-i)*(arr[l]-i);
            }
            miner=min(miner,counter);
            }
            cout<<miner;
            return 0;
        }


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String S = sc.next();
		int month = Integer.parseInt(S.substring(5, 7));
		int day = Integer.parseInt(S.substring(8,10));
		String ans = "Heisei";
		if (month > 4) {
			ans = "TBD";
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int a[3];cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[2]-a[1]+(a[1]-a[0])/2+(a[1]-a[0])%2*2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
    int i,x[3];
    for(i=0;i<3;i++)
        cin>>x[i];
    sort(x,x+3);
    cout<<x[2]*10+x[1]+x[0]<<endl;
    return 0;

}


Measured memory_bytes: 256
import heapq  
def priority(klr):
    return abs(klr[1]-klr[2])
              
def process(KP):
    q = []    
    for kp in KP:
        if kp[0] < len(q) and len(q) > 0 and q[0] < kp[1]:
            heapq.heappop(q)
        if kp[0] >= len(q):
            heapq.heappush(q, kp[1])
    return sum(q)
              
def solve():  
    N = int(input())
    KLR = []  
    for _ in range(N):
        klr = list(map(int, input().split()))
        klr[0] -= 1 # convert to 0-based index to avoid confusion                                                                                                                                           
        KLR.append(klr)
    ans = 0   
    L = []    
    R = []    
    for klr in KLR:
        if klr[1] > klr[2]:
            ans += klr[2]
            L.append((klr[0], klr[1]-klr[2]))
        elif klr[1] < klr[2]:
            ans += klr[1]
            R.append((N-1-klr[0]-1, klr[2]-klr[1]))
        else: 
            ans += klr[1]
    L.sort(key=lambda kp: kp[0])
    R.sort(key=lambda kp: kp[0])
    ans += process(L)
    ans += process(R)
    print(ans)
              
T = int(input())
              
for _ in range(T):
    solve()   
              
              

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector< pair<int,int> > A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i].first;
        A[i].second = i+1;
    }

    sort(A.begin(), A.end());

    for(auto e: A) {
        cout << e.second << endl;
    }
    return 0;
}


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

typedef vector<int> vi;
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define loopiRev(i,s,e) for(int i=s; i >= e; i--)
#define PI 3.14159265359
#define x first
#define y second
#define point pair<double,double>
#define len(s)   (int)s.length()
#define sz(v)    (int)v.size()
#define all(a)   a.begin(),a.end()
#define clr(x, val)	memset((x), (val), sizeof(x))

void initialize(vector<int> &F, int n){
    F = vector<int> (n+1, 0);

    for(int i=2; i*i  <= n; i++){
        if(F[i] == 0)
            for(int k=i*i; k <=n ; k+= i)
                if(F[k] == 0) F[k] = i;
    }
}

//you don't know math, unless you can do math!
int l,n;
vector<int> cuts;
ll dp[1100][1100];

ll solve(int i, int j){
    ll &ret= dp[i][j];
    if(ret != -1)
        return ret;

    int cur= lower_bound(cuts.begin(), cuts.end(), i+1) - cuts.begin();
    if(cur == cuts.size() || cuts[cur] >= j)
        return ret= 0;



    ret= 10000000;
    while(cur < n && cuts[cur] < j){
        ret = min(ret, solve(i, cuts[cur]) + solve(cuts[cur], j) + j - i);
        cur++;
    }

    return ret;
}
int main() {
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n,t; cin>>n>>t;
    vector<int> times(n);

    loop(i, n) cin>>times[i];

    int total=t;
    loop1(i, n-1){
        if(times[i] - times[i-1] < t)
            total+= times[i]-times[i-1];
        else
            total+= t;
    }

    cout<<total;

}


Measured memory_bytes: 1024
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
    
signed main(){
        int n,m; cin>>n>>m;
        int a[1000],b[1000],c[1000],dist[100][100];
        for(int i=0; i<m; ++i){ cin >> a[i] >> b[i] >> c[i];a[i]--,b[i]--;
            }
            for(int i=0;i<n; ++i){ for(int j = 0;j<n;++j){
                if(i==j)
                dist[i][j]=0;
            else
                dist[i][j]=inf;
            } }
            
            for(int i=0;i<m;++i){ dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]); dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
            }
            for(int k=0;k<n;++k){ for(int i = 0; i < n; ++i){
                for(int j = 0; j < n; ++j){
                    dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
                } }
            }
            int ans=m; for(int i=0;i<m;++i){
                bool shortest=false;
                for(int j = 0; j < n; ++j) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
                if(shortest==true){
                    ans=ans-1; }
            }
            cout << ans << endl;
    return 0;
        }

Measured memory_bytes: 384
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // input from txt （提出時にこの箇所は削除すること）
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int N, K, j=1;
    cin>>N>>K;
    for (int i=0;i<N;i++){
        if(j<K){
            j*=2;
        }
        else{
            j+=K;
        }
    }
    cout<<j<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val as = input.nextLine().split(" ").map(_.toInt)
      val Array(a1, a2, a3) = as

      val diff = as.sortBy(identity).sliding(2).map(ns => Math.abs(ns(0) - ns(1))).sum

      output.println(diff)
    }

  }

}


Measured memory_bytes: 27332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,q;
    cin >> n>> q;
    vector<pair<string,int> > s(n);
    for(int i=0;i<n;i++){
        cin>>s[i].first>>s[i].second;
        }
    int i=0,time=0;
    while(i<s.size()){
        if(s[i].second<=q){
            time+=s[i].second;
            cout<<s[i].first<<" "<<time<<endl;
            i++;
        }
        else{
            time+=q;
            s.push_back(make_pair(s[i].first,s[i].second-q));
            i++;
        }
    }
  return 0;
}


Measured memory_bytes: 8324
#include<stdio.h>
int gcd(int a,int b){
  int temp;
  if(a<b){
    temp=b;
    b=a;
    a=temp;
  }
  int r=a%b;
  while(r){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}
int main(){
  int x,y;
  scanf("%d %d",&x,&y);
  int ans=x+y+1;
  ans-=gcd(x,y);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c;
    if(a*b<=c)
    {
        cout<<a*b<<endl;
    }
    else
    {
        cout<<c<<endl;
    }
    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main(){
int n,m;
cin>>n>>m;
ll a[n],b[n],c[m],d[m];
rep(i,n){
    cin>>a[i]>>b[i];
}
rep(i,m){
    cin>>c[i]>>d[i];
}
rep(i,n){
    ll point=INF;
    int ans=0;
    rep(k,m){
ll A=abs(a[i]-c[k])+abs(b[i]-d[k]);
if(point>A){
    point=A;
ans=k+1;
}
    }
    cout<<ans<<endl;
}

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, a[109];
int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> a[i];
    sort(a, a + N, greater<int>());
    int ret = 0;
    for (int i = 0; i < N; i++)
        if (i % 2 == 0)
        {
            ret += a[i];
        }
        else
        {
            ret -= a[i];
        }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int weight[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
	int n;
	while( cin >> n, n ){
		int j = 0;
		int ans[10];
		for( int i = 9; i >= 0; i-- ){
			if( n == 0 ) break;
			if( n >= weight[i] ){
				n -= weight[i];
				ans[j++] = weight[i];
			}
		}
		for( int i = j - 1; i >= 0; i-- ){
			if( i == 0 ){
				cout << ans[i] << endl;
				break;
			}
			cout << ans[i] << ' ';
		}
	}
}

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

int N, M;
int k[10], s[10][10], p[10];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    for (int i = 0; i < M; ++i) {
        cin >> p[i];
    }
    int ans = 0;
    for (int bit = 0; bit < 1 << N; ++bit) {
        bool ok = true;
        for (int i = 0; i < M; ++i) {
            int pp = 0;
            for (int j = 0; j < k[i]; ++j) {
                if (bit >> s[i][j] & 1) pp ^= 1;
            }
            if (pp != p[i]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
}

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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0;
}

int rec(int v, const vector<vector<int>> &g, vector<int> &dp)
{
  if (dp[v] > -1) return dp[v];
  int res = 0;
  for (auto nv: g[v]) chmax(res, rec(nv, g, dp)+1);
  return dp[v] = res;
}

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

  // 隣接リスト
  vector<vector<int>> G(N, vector<int>());
  for (int i=0; i<M; i++) {
    int s, t;
    cin >> s >> t;
    s--, t--;
    G[s].push_back(t);
  }

  vector<int> dp(N, -1);
  int ans = 0;
  for (int i=0; i<N; i++) chmax(ans, rec(i, G, dp));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int mod = 1e9 + 7;
int s, fact[N];

int add(int x, int y) {
	if (x + y >= mod) {
		return x + y - mod;
	}
	return x + y;
}

int mul(int x, int y) {
	return (long long) x * y % mod;
}

int exp(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) {
			ans = mul(ans, x);
		}
		x = mul(x, x);
		y >>= 1;
	}
	return ans;
}

int inv(int x) {
	return exp(x, mod - 2);
}

int choose(int x, int y) {
	return mul(fact[x], inv(mul(fact[y], fact[x - y])));
}

int ways(int x, int i) {
	if (x < 0) {
		return 0;
	}
	return choose(x + i - 1, x);
}

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

	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = mul(fact[i - 1], i);
	}

	cin >> s;

	int ans = 0;
	for (int i = 1; i < s; i++) {
		int ns = s - i * 3;
		ans = add(ans, ways(ns, i));
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3664
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

main = do
  [n, k, x, y] <- concat <$> readInts 4
  let a = (n - k) in print $ f n k x y 0

f n k x y acc | n == 0    = acc
              | k > 0     = f (n - 1) (k - 1) x y (acc + x)
              | otherwise = f (n - 1) k x y (acc + y)


Measured memory_bytes: 380
#include <cstdio>

typedef long long ll;

const int MAXN = 1000;

ll X[MAXN + 5], Y[MAXN + 5]; int N;

ll abs(ll x) {
	return x >= 0 ? x : -x;
}

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%lld%lld", &X[i], &Y[i]);
	int type = ((X[1] + Y[1]) & 1);
	for(int i=1;i<=N;i++) {
		if( type != ((X[i] + Y[i]) & 1) ) {
			type = -1;
			break;
		}
	}
	if( type == -1 ) {
		puts("-1");
		return 0;
	}
	else if( type == 0 ) {
		printf("%d\n%d", 40, 1);
		for(int i=0;i<39;i++)
			printf(" %lld", (1LL<<i));
		puts("");
		for(int i=1;i<=N;i++) {
			putchar('L'), X[i]++;
			for(int j=0;j<38;j++) {
				ll t1 = (1LL << j), t2 = (1LL << (j + 1)), t3 = (1LL << (j + 2));
				if( abs(X[i] % t2) == t1 ) {
					if( abs(Y[i] % t3) + abs((X[i] + t1) % t3) == t2 )
						putchar('L'), X[i] += t1;
					else putchar('R'), X[i] -= t1;
				}
				else {
					if( abs(X[i] % t3) + abs((Y[i] + t1) % t3) == t2 )
						putchar('D'), Y[i] += t1;
					else putchar('U'), Y[i] -= t1;
				}
			}
			ll t1 = (1LL << 38), t2 = (1LL << 39), t3 = (1LL << 40);
			if( abs(X[i] % t2) == t1 ) {
				if( abs(Y[i] % t3) + abs((X[i] + t1) % t3) == t2 )
					puts("R"), X[i] -= t1;
				else puts("L"), X[i] += t1;
			}
			else {
				if( abs(X[i] % t3) + abs((Y[i] + t1) % t3) == t2 )
					puts("U"), Y[i] -= t1;
				else puts("D"), Y[i] += t1;
			}
		}
	}
	else {
		printf("%d\n", 40);
		for(int i=0;i<40;i++)
			printf("%lld ", (1LL<<i));
		puts("");
		for(int i=1;i<=N;i++) {
			for(int j=0;j<39;j++) {
				ll t1 = (1LL << j), t2 = (1LL << (j + 1)), t3 = (1LL << (j + 2));
				if( abs(X[i] % t2) == t1 ) {
					if( abs(Y[i] % t3) + abs((X[i] + t1) % t3) == t2 )
						putchar('L'), X[i] += t1;
					else putchar('R'), X[i] -= t1;
				}
				else {
					if( abs(X[i] % t3) + abs((Y[i] + t1) % t3) == t2 )
						putchar('D'), Y[i] += t1;
					else putchar('U'), Y[i] -= t1;
				}
			}
			ll t1 = (1LL << 39), t2 = (1LL << 40), t3 = (1LL << 41);
			if( abs(X[i] % t2) == t1 ) {
				if( abs(Y[i] % t3) + abs((X[i] + t1) % t3) == t2 )
					puts("R"), X[i] -= t1;
				else puts("L"), X[i] += t1;
			}
			else {
				if( abs(X[i] % t3) + abs((Y[i] + t1) % t3) == t2 )
					puts("U"), Y[i] -= t1;
				else puts("D"), Y[i] += t1;
			}
		}
	}
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t x;
    std::cin >> x;

    auto q = x / 11;
    auto r = x % 11;

    int64_t ans = q * 2;
    if (r > 6) {
        ans ++;
    }

    if (r > 0) {
        ans ++;
    }

    std::cout << ans << std::endl;

    return 0;
}


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

def main():
    N, K = map(int, input().split())
    d = set(input().strip().split())

    tmp = N
    while True:
        s = set(list(str(tmp)))
        if len(s & d) == 0:
            print(tmp)
            break
        tmp += 1

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(){
#define int ll
    int n,l;
    cin>>n>>l;
    vector<string> s(n);
    rep(i,0,n)cin>>s[i];
    sort(s.begin(),s.end());
    rep(i,0,n)cout<<s[i];
}

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

using namespace std;

const int inf = INT_MAX;

int n, m;
int a[123], b[123];
int c[123], d[123];

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> c[i] >> d[i];
    }
    for (int i = 1; i <= n; i++) {
        int dist = abs(a[i] - c[1]) + abs(b[i] - d[1]);
        int res = 1;
        for (int j = 2; j <= m; j++) {
            if (dist > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                res = j;
            }
        } 
        cout << res << "\n";
    }    
    return 0;
}

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

#define NMAX 2000001

void CountingSort (int *,int *,int);
int n;

int main (void)
{
  int *a,*b,i,k,result;
  
  //input
  scanf ("%d",&n);

  //ヒープメモリ確保
  a = malloc(sizeof(int) * (n + 1));
  b = malloc(sizeof(int) * (n + 1));

  //input
  for (i = 1 ; i <= n ; i++){
    scanf ("%d",&a[i]);
  }

  //CountingSort関数で用いるC[i]の要素数の決定
  k = 0;
  for (i = 1 ; i <= n ; i++){
    if (k < a[i])
      k = a[i];
    }

  //CountingSort関数へ移動
  CountingSort (a,b,k);

  //output
  for (i = 1 ; i <= n ; i++){
    printf ("%d",b[i]);
    if (i < n)
      printf (" ");
    else
      printf ("\n");
  }

  //ヒープメモリ解放
  free(a);
  free(b);

  return 0;
}

void CountingSort (int *a,int *b,int k)
{
  int i,j,*c;

  //ヒープメモリ確保
  c = malloc(sizeof(int) * k);

  for (i = 0 ; i <= k ; i++){
    c[i] = 0;
  }

  //C[i] に i の出現数を記録する
  for (j = 1 ; j <= n ; j++){
    c[a[j]]++;
  }

  //C[i] に i 以下の数の出現数を記録する
  for (i = 1 ; i <= k ; i++){
    c[i] = c[i] + c[i-1];
  }

  for (j = n ; j >= 1 ; j--){
    b[c[a[j]]] = a[j];
    c[a[j]]--;
  }

  //ヒープメモリ解放
  free(c);

  return;
}

Measured memory_bytes: 16056
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;

int main() {
	string s;
	ll a;
	cin >> a >> s;
	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout<< "red" <<endl;
	}
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){

  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj_list(n);
  vector<int> height(n);
  vector<bool> is_good(n,true);
  int tmp_a, tmp_b;
  rep(i,n) cin >> height[i];
  rep(i,m){
    cin >> tmp_a >> tmp_b;
    tmp_a--; tmp_b--;
    adj_list[tmp_a].emplace_back(tmp_b);
    adj_list[tmp_b].emplace_back(tmp_a);
  }

  rep(i,n){
    if (!is_good[i]) continue;
    rep(j, adj_list[i].size()){
      int dest = adj_list[i][j];
      if (height[i] > height[dest]){
        is_good[dest] = false;
      } else if (height[i] == height[dest]) {
        is_good[i] = false;
        is_good[dest] = false;
        break;
      } else {
        is_good[i] = false;
        break;

      }
    }
  }

  int ans = 0;
  rep(i,n){
    if (is_good[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  long long ans=0;
  
  for(int b=k+1;b<=n;b++){
    int p=n/b;
    ans+=(b-k)*p;
    if(n%b!=0) ans+=max(0,(n-p*b)-max(k,1)+1);
  }
  
  cout << ans << endl;
}

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

int main() {
	char s;
	int n,a[4][13 + 1] = {0};
	int num;
	
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> s >> num;
		num = num - 1;
		if ( s == 'S' ) a[0][num]++;
		else if ( s == 'H' ) a[1][num]++;
		else if ( s == 'C' ) a[2][num]++;
		else if ( s == 'D' ) a[3][num]++;
	}
	for ( int i = 0; i < 4; i++ ) {
		for ( int j = 0; j < 13; j++ ) {
			if ( i == 0 ) s = 'S';
			if ( i == 1 ) s = 'H';
			if ( i == 2 ) s = 'C';
			if ( i == 3 ) s = 'D';
			
			if ( a[i][j] == 0 ) {
				cout << s << " " << j + 1 << endl;
			} 
		}
	}
	
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 

ll mod = 1e9 + 7;

#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
// cout<<endl;


int main()
{
	fastio();
	string s;
	cin>>s;
	int n = s.length();
	int cnt = 0;
	rep(i, n/2)
	{
		if(s[i] != s[n-i-1])
			cnt++;
	}
	cout<<cnt<<endl;
}

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

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> II;
typedef vector<II> VII;

#define REP(x, n) for (int x = 0; x < (n); ++x)
#define INF (1e9 + 1)
#define EPS 1e-9
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    cin >> s;
    if (s == "Sunny") {
        cout << "Cloudy\n";
    }
    else if (s == "Cloudy") {
        cout << "Rainy\n";
    }
    else if (s == "Rainy") {
        cout << "Sunny\n";
    }
    return 0;
}

Measured memory_bytes: 256
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();
    if (a+b+c >= 22){
      System.out.println("bust");
    } else {
      System.out.println("win");
    }
  }
}

Measured memory_bytes: 24020
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut map = std::collections::HashMap::new();
    for i in 0..n {
        let p = map.entry(i as i64 + a[i]).or_insert(0);
        *p += 1i64;
    }

    let mut ans = 0;
    for i in 0..n {
        let p = map.entry(i as i64 - a[i]).or_insert(0);
        ans += *p;
    }
    println!("{}", ans);
}


Measured memory_bytes: 18356
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;

int a[200010];
int b[200010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    multiset<ll> st;
    REP(i, n){
        ll a, b; cin >> a >> b;
        if(a==1){
            cout << st.count(b) << endl;
        }else if(a==0){
            st.insert(b);
            cout << st.size() << endl;
        }else if(a==2){
            st.erase(b);
        }else{
            ll c; cin >> c;
            for(auto itr=st.lower_bound(b); itr!=st.upper_bound(c); ++itr) cout << *itr << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 12316
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

ll R, C, K;

const ll MAXN = 3002;
ll S[MAXN][MAXN];
ll dp[MAXN][MAXN][4];

int main()
{
    cin >> R >> C >> K;

    rep (i, K)
    {
        ll x, y;
        cin >> x >> y;
        cin >> S[x][y];
    }

    rep (i, R + 1)
    rep (j, C + 1)
    {
        dp[i][j][0] = 0;
    }

    dp[1][1][0] = 0;
    if (S[1][1] >= 0) { dp[1][1][1] = S[1][1]; }

    ll ans = 0;

    for (ll i=1;i<=R;++i)
    for (ll j=1;j<=C;++j)
    for (ll k=1;k<=3;++k)
    {
        const auto a = dp[i - 1][j][3] + S[i][j];
        const auto b = dp[i][j - 1][k - 1] + S[i][j];
        const auto c = dp[i][j - 1][k];

        const auto score = max(a, max(b, c));
        dp[i][j][k] = score;
        ans = max(ans, score);
    }

    cout << ans << endl;
}


Measured memory_bytes: 355344
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
ab = []
for i in range(n):
    a,b = inpl()
    ab.append((a-b,a+b,b))
# ab.sort()
ab.sort(key=lambda x:x[1])
res = 1
r = ab[0][1]
for i in range(1,n):
    if ab[i][0] < r:
        continue
    r = ab[i][1]
    res += 1
print(res)

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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for(ll i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(RALL(h));
    ll ans = 0;
    for(ll i = k; i < n; i++) {
        ans += h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
 
class Main {
 
	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);
 
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int C = stdIn.nextInt();
		boolean D = false;
		
		
		if(A==B){
			if(B==C){
				System.out.println("No");
			}else{
				System.out.println("Yes");
			}
		}else{
			if(B==C){
				System.out.println("Yes");
			}else if(A==C){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
 
	}
    
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const int INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

int main() {
    int X, N;
    cin >> X >> N;
    vector<int> A(N);
    rep(i, N)cin >> A[i];
    
    int ans = 1000;
    
    for (int i = X - 105; i <= X + 105; i++){
        bool flag = false;
        rep (j, N){
            if (i == A[j]){
                flag = true;
            }
        }
        if (!flag){
            if (abs(X - i) < abs(X - ans)){
                ans = i;
            }
        }
    }
    cout << ans;
       
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
int moguru(int[][100],int);
int n,ans[100];
int main(){
  int i,j,a[100][100],mita[100],now,to,leng;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    ans[i]=-1;
  }
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
    a[i][j] = -1;
  
  for(i=0;i<n;i++){
    scanf("%d",&now);
    scanf("%d",&now);
    for(j=0;j<now;j++){
      scanf("%d %d",&to,&leng);
      a[i][to] = leng;
    }
  }
  ans[0]=0;
  moguru(a,0);
  for(i=0;i<n;i++){
    printf("%d %d\n",i,ans[i]);
  }

}

int moguru(int a[][100],int now){
  int i;
  for(i=0;i<n;i++){
    if(a[now][i] == -1)
      continue;
    if(ans[now]+a[now][i] < ans[i] || ans[i] == -1){
      ans[i]= ans[now]+a[now][i];
      moguru(a,i);
    }
	
  }
  return 1;

}



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

typedef long long ll;


void solve(long long a, long long b, long long c, long long d){
  cout << max({a * c, b * d, b * c, a * d}) << endl;
}

int main() {
  long long a;
  scanf("%lld",&a);
  long long b;
  scanf("%lld",&b);
  long long c;
  scanf("%lld",&c);
  long long d;
  scanf("%lld",&d);
  solve(a, b, c, d);
  return 0;
}


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

const int N = 1e5 + 5;
const int inf = 1e9;

ll dp[N];

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  a[0] = dp[0] = inf;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = inf;
  }
  dp[1] = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i-j >= 1) {
        dp[i] = min(dp[i-j] + abs(a[i] - a[i-j]), dp[i]);
      }
    }
  }
  cout << dp[n] << '\n';
  return 0;
}

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

H, W, M = map(int, input().split())
hw = [[int(i) for i in input().split()] for _ in range(M)]

hl = [0] * H
wl = [0] * W
mem = set()

for h, w in hw :
  hl[h - 1] += 1
  wl[w - 1] += 1
  mem.add((h - 1, w - 1))
  
mh = max(hl)
mw = max(wl)

if mh == 0 :
  print(mw)
elif mw == 0 :
  print(mh)
else :
  hs = []
  ws = []
  for i, y in enumerate(hl) :
    if y == mh :
      hs.append((i, y))
  for i, x in enumerate(wl) :
    if x == mw :
      ws.append((i, x))


  ret = 0
  for x, w in ws :
    flag = False
    for y, h in hs :
      if (y, x) in mem :
        ret = max(ret, w + h - 1)
      else :
        ret = max(ret, w + h)
        flag = True
        break
    if flag :
      break
      
  print(ret)

Measured memory_bytes: 175612
#include<iostream>
#include<string>
using namespace std;
int n,count;
string s;
int main(){
    cin >> n >> s ;
    for(int i = 2;i<n;i++){
    if(s[i] == 'C'){
        if(s[i-2] == 'A'&&s[i-1] == 'B'){
        count += 1;
        }
    }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256