akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;


#define NUM 200
 
int V;
vector<int> G[NUM];
int match[NUM];
bool used[NUM];
 
void add_edge(int from,int to){
    G[from].push_back(to);
    G[to].push_back(from);
}
 
int dfs(int node_id){
    used[node_id] = true;
 
    for(int i = 0; i < G[node_id].size(); i++){
        int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
        if((pair_id < 0)||(used[pair_id] == false && dfs(pair_id) == true)){
            match[node_id] = adj_node_id;
            match[adj_node_id] = node_id;
            return true;
        }
    }
    return false;
}
 
 
int bipartie_matching(){
    int ret = 0;
    for(int i = 0; i < V; i++)match[i] = -1;
    for(int node_id = 0; node_id < V; node_id++){
        if(match[node_id] < 0){
            for(int i = 0; i < V; i++)used[i] = false;
            if(dfs(node_id)){
                ret++;
            }
        }
    }
    return ret;
}
 
 
int main(){
    int N;
    cin >> N;
    int a[N],b[N];
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i];
    }
    int c[N],d[N];
    for(int i=0;i<N;i++){
        cin >> c[i] >> d[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(a[i]<c[j]&&b[i]<d[j]) add_edge(i,N+j);
        }
    }
    V = 2*N;

    cout << bipartie_matching() << endl;;
 
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

/**
 * The Number of Island
 */
public class Main {

	final static int SEA = 0;
	final static int LAND = 1;
	final static int VISITED = -1;

	final static int[] V = { 1, -1, 0, 0 };
	final static int[] H = { 0, 0, 1, -1 };

	static LinkedList<Integer> xs, ys;
	static int count;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (true) {
			// load map
			int[][] map = new int[12][12];
			xs = new LinkedList<Integer>();
			ys = new LinkedList<Integer>();
			for (int i = 0; i < 12; i++) {
				line = br.readLine();
				for (int j = 0; j < 12; j++) {
					map[i][j] = line.charAt(j) - '0';
				}
			}

			// solve
			count = 0;
			for (int i = 0; i < 12; i++) {
				for (int j = 0; j < 12; j++) {
					if (map[i][j] == LAND) {
						xs.add(i);
						ys.add(j);
						while (!xs.isEmpty() && !ys.isEmpty()) {
							visit(map);
						}
						count++;
					}
				}
			}

			// output.
			System.out.println(count);

			// next
			line = br.readLine();
			if (line == null) {
				break;
			} else {
				continue;
			}
		}
		//
	}

	public static void visit(int[][] map) {

		int x, y;
		x = xs.remove();
		y = ys.remove();

		map[x][y] = VISITED;

		// next choices
		for (int i = 0; i < 4; i++) {
			int xv, yh;
			xv = x + V[i];
			yh = y + H[i];
			if (xv >= 0 && xv < 12 && yh >= 0 && yh < 12
					&& map[xv][yh] != VISITED && map[xv][yh] != SEA) {
				xs.add(xv);
				ys.add(yh);
			}
		}
	}
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n, c, k;
int a[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d%d%d", &n, &c, &k );
	lp ( i, 0, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work

	sort ( a, a+n );

	int cc = 0, lt = -1, nc = 0;
	lp ( i, 0, n ){
		if ( lt < a[i] || nc == c ){
			++cc;
			lt = a[i] + k;
			nc = 1;
		}else ++nc;
	}

	printf ( "%d\n", cc );
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int h,w;
    char a[55][55];
   int b[55][55];
    cin>>h>>w;
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
        cin>>a[i][j];
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
    {
        int num=0;
        if (a[i][j]=='.')
        {
             if (a[i-1][j-1]=='#')
               num++;
             if (a[i-1][j]=='#')
                num++;
             if (a[i-1][j+1]=='#')
                 num++;
             if (a[i][j-1]=='#')
                num++;
             if (a[i][j+1]=='#')
               num++;
             if (a[i+1][j-1]=='#')
               num++;
              if (a[i+1][j]=='#')
                num++;
             if (a[i+1][j+1]=='#')
               num++;
             a[i][j]='0'+num;
        }
    }
    for (int i=0;i<h;i++)
    {
        for (int j=0;j<w;j++)
           printf("%c",a[i][j]);
      printf("\n");
    }
    return 0;
}


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

MOD = 1000000007  # type: int

def solve(N: int, X: int, S: "List[int]"):
    fact = [0] * (N + 1)
    fact[1] = 1
    for i in range(2, N + 1):
        fact[i] = fact[i - 1] * i

    memo = [[-1] * (X + 1) for _ in range(N + 1)]
    S.sort(reverse=True)
    def rec(idx, x, d=0):
        #suf = ''.join(['  ' for _ in range(d)])
        #print(suf, idx, x)
        if memo[idx][x] >= 0:
            return memo[idx][x]
        if idx == N - 1:
            memo[idx][x] = x % S[idx]
            return memo[idx][x]
        ret = 0

        ret += rec(idx + 1, x, d + 1) * (N - idx - 1)
        ret += rec(idx + 1, x % S[idx], d + 1)

        #for i in range(idx + 1, N):
        #    ret += rec(i, x, d + 1) * (N - idx - 1)
        #    ret += rec(i, x % S[idx], d + 1)
        #print(suf, idx, x, ' =>', ret)
        memo[idx][x] = ret
        return ret

    ret = rec(0, X)
    print(ret % MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    S = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 222192
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll pw(ll a, ll x){
	ll ret = 1;
	while(x){
		while(!(x&1)){
			(a *= a) %= mod;
			x /= 2;
		}
		(ret *= a) %= mod;
		x--;
	}
	return ret;
}

int c[200010];
ll sum[200010];
int main(){
	ll i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> c[i];
	}
	sort(c,c + n);
	ll ans = 0;
	for(i=0;i<n;i++){
		(ans += pw(2,2*n - 2)*(n + 1 - i)%mod*c[i]%mod) %= mod;
	}
	cout << ans << endl;
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  int ans;
  int N;
  cin >> N;
  vector<LL> a(N);
  FOR(i, 0, N) { cin >> a[i]; }

  vector<LL> b(N);

  int a_index = N - 1;
  int b_index = 0;
  while (a_index >= 0) {
    b[b_index] = a[a_index];
    a_index -= 2;
    b_index++;
  }

  a_index = N % 2;
  while (a_index < N) {
    b[b_index] = a[a_index];
    a_index += 2;
    b_index++;
  }

  FOR(i, 0, N) { cout << b[i] << ' '; }

  cout << '\n';

  return 0;
}

Measured memory_bytes: 5376
import java.util.*;
 
class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        String N = sc.next();
        String a = "7";
 
        for(int i=0; i<3; i++){
            if(N.charAt(i)==a.charAt(0)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35692
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)


int main() {
    int n, a; cin >> n >> a;
    vector<int> X(n);
    rep(i, n) cin >> X[i];

    vector<vector<vector<ll>>> dp(55, vector<vector<ll>>(2600, vector<ll>(55, 0)));
    
    ll sum = 0; dp[0][0][0] = 1;
    
    rep(i, n){
        rep(j, 2501){
            rep(k, i+1){
                dp[i+1][j+X[i]][k+1] += dp[i][j][k];
                dp[i+1][j][k] += dp[i][j][k];
            }
        }
    }
    rep(i, 2501){
        for(int k = 1; k <= 50; k++){
            double d = k;
            if(i / d == a){;
                sum +=  dp[n][i][k];             
            }
        }
    }
    cout << sum << ln;
}




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

int main() {
	int H, W, N, sx, sy;
	bool check = true;
	static char S[200000], T[200000];
	cin >> H >> W >> N >> sx >> sy;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	int L, R, U, D;
	L = R = sy, U = D = sx;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') {
			L--;
		}
		if (S[i] == 'R') {
			R++;
		}
		if (S[i] == 'U') {
			U--;
		}
		if (S[i] == 'D') {
			D++;
		}
		if (L == 0 || R == W + 1 || U == 0 || D == H + 1) {
			check = false;
			break;
		}
		if (T[i] == 'L') {
			R--;
			if (R <= 0) R = 1;
		}
		if (T[i] == 'R') {
			L++;
			if (L > W) L = W;
		}
		if (T[i] == 'U') {
			D--;
			if (D <= 0) D = 1;
		}
		if (T[i] == 'D') {
			U++;
			if (U > H) U = H;
		}
	}
	if (check) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  long n,m;
  cin >> n >> m;
  vector<long> x(n);
  vector<long> y(n);
  vector<long> z(n);
  vector<long> rx(n);
  vector<long> ry(n);
  vector<long> rz(n);
  rep(i,n){
    cin >> x.at(i) >> y.at(i) >> z.at(i);
    rx.at(i) = -1*x.at(i);
    ry.at(i) = -1*y.at(i);
    rz.at(i) = -1*z.at(i);
  }
  long ans = 0;
  rep(a,2){
    rep(b,2){
      rep(c,2){
        vector<long> tmp(n);
        rep(i,n){
          long tmpx,tmpy,tmpz;
          if(a){
            tmpx = rx.at(i);
          }else{
            tmpx = x.at(i);
          }
          if(b){
            tmpy = ry.at(i);
          }else{
            tmpy = y.at(i);
          }
          if(c){
            tmpz = rz.at(i);
          }else{
            tmpz = z.at(i);
          }
          //if(tmpx + tmpy + tmpz < 0) break;
          tmp.at(i) = tmpx + tmpy + tmpz;
        }
        sort(tmp.begin(),tmp.end(),greater<long>());
        long sum = 0;
        rep(i,m){
          //if(tmp.at(i) < 0) break;
          sum += tmp.at(i);
        }
        ans = max(ans,sum);
      }
    }
  }
  cout << ans << endl;
}

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

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

def main():
    mod=10**9+7
    M,K=MI()
    N=pow(2,M)
    
    if K>=N or (M==1 and K==1):
        print(-1)
    elif M==1 and K==0:
        print(0,0,1,1)
    else:
        from collections import deque
        dq=deque()
        dq.append(K)
        for i in range(N):
            if i!=K:
                dq.append(i)
                dq.appendleft(i)
        dq.append(K)
        
        ans=[]
        while len(dq)!=0:
            ans.append(dq.pop())
        print(' '.join(map(str, ans)))
    

                

main()


Measured memory_bytes: 97720
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] s = new int[n];
        int a = 0;
        for(int i = 0; i < n; i++){
            s[i] = scan.nextInt();
            a += s[i];
        }
        Arrays.sort(s);
        for(int i = 0; i < n; i++){
            if(a % 10 == 0 && s[i] % 10 != 0){
                a -= s[i];
            }else if(a % 10 != 0){
                System.out.println(a);
                System.exit(0);
            }
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include<string>
#include <math.h>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std ;
typedef long long int ll ;

int main (){
	ll a , sum = 0  ;
	cin >> a ;
	for (ll i = 0; i <= a; i++)
	{
		if (!(i%3 == 0 || i%5 == 0))
		{
			sum += i ;
		}
		
	}
	cout << sum << endl ;
	
return 0 ;
}

Measured memory_bytes: 3188
n=int(input())
rec=[False]*n
for i in range(n):
    a,b=map(int,input().split())
    if a==b:
        rec[i]=True
for i in range(n-2):
    if rec[i] and rec[i+1] and rec[i+2]:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 62488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int T = in.nextInt();
		int x[]=new int[1001];
		
		for(int i=0;i<1001;i++) {
			x[i]=10000;
		}
		
		
		for(int i=0;i<N;i++) {
			int a=in.nextInt();
			x[a]=in.nextInt();
		}
		int min=10000;
		int minnb=10000;
		
		for(int i=1;i<1001;i++) {
			if(x[i]<=T) {
				minnb=Math.min(minnb, i);
			}
		}
		
		if(minnb==10000) {
			System.out.println("TLE");
		}else {
			System.out.println(minnb);
		}
		

	}
}

Measured memory_bytes: 24020
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
 
const int maxv = 3005;
 
double cmp(pair<int, int> a)
{
	if(a.first && a.second) return (double(100*a.second)/(a.first+a.second));
	else return 0;
}
 
int main(void)
{
	int a, b, c, d, e, f;
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
 
	vector<int> poss;
	for(int i = 0;i < maxv;i++)
	{
		for(int j = 0;j < maxv;j++) poss.push_back(-(i*c+j*d));
	}
 
	sort(poss.begin(), poss.end());
	poss.resize(int(unique(poss.begin(), poss.end())-poss.begin()));
 
	pair<int, int> cur = {0, 0};
	for(int i = 0;i < maxv;i++)
	{
		for(int j = 0;j < maxv;j++)
		{
			int w = (i*a+j*b)*100;
			if(w > f) continue;
			int maxd = min(f-w, e*(w/100));
			int r = (-*lower_bound(poss.begin(), poss.end(), -maxd));
			if(cmp(cur) <= cmp({w, r})) cur = {w, r};
		}
	}
	printf("%d %d\n", cur.first+cur.second, cur.second);
}

Measured memory_bytes: 67936
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    vector<int> odd(1e5+1,0);
    vector<int> even(1e5+1,0);
    for(int i=0;i<n;i++){
        cin>>v[i];
        if(i%2==0)even[v[i]]++;
        else odd[v[i]]++;
    }
    int me1=0,me2=0,mo1=0,mo2=0,besto=0,beste=0;
    for(int i=0;i<=1e5;i++){
        if(mo1<=odd[i]){
            besto=i;
            mo2=mo1;
            mo1=odd[i];
        }
        else if(mo2<odd[i]){
            mo2=odd[i];
        }
        if(me1<=even[i]){
            beste=i;
            me2=me1;
            me1=even[i];
        }
        else if(me2<odd[i]){
            me2=even[i];
        }
    }
    if(beste==besto){
        cout<<min(n/2-me1+n/2-mo2,n/2-me2+n/2-mo1)<<endl;
    }
    else
        cout<<n/2-me1+n/2-mo1<<endl;
    return 0;
}


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

using namespace std;

#define rep(i, a) for (int (i) = 0; (i) < (a); (i)++)
#define reps(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define MP(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(v) (v).begin(), (v).end()


int main()
{
	int n, m;
	cin >> n >> m;
	cout << n * n - m << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <cstdio>
using namespace std;

int n, m, ans, e, w[110][110], path[110][110];
vector<int> G[110], W[110];
pair<int, int> E[1001];
int main()
{
    memset(path, 0x3f, sizeof(path));
    scanf("%d%d", &n, &m);
    for(int i = 0 ; i < m ; i++ )
    {
        int a, b ,c;
        scanf("%d%d%d", &a, &b ,&c);
        G[a].push_back(b);
        G[b].push_back(a);
        w[a][b] = w[b][a] = path[b][a] = path[a][b] = c;
        E[e++] = {a, b};
    }
    for(int i = 1 ; i <= n ; i++ ) path[i][i] = 0;
    for(int k = 1 ; k <= n ; k++ )
        for(int i = 1 ; i <= n ; i++ )
            for(int j = 1 ; j <= n ; j++ )
                if( path[i][j] > path[i][k] + path[k][j] )
                    path[i][j] = path[i][k] + path[k][j];
    for(int k = 0 ; k < e ; k++ )
    {
        bool flag = 0;
        int a = E[k].first, b = E[k].second, wt = w[a][b];
        for(int i = 1 ; i <= n ; i++ )
            if( path[i][a] + wt == path[i][b] or path[i][b] + wt == path[i][a] ) flag = 1;
        if( !flag ) ans++;
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = (int)1e6;
template<class Type> class MaxHeap
{
    public:
      Type *heap;
      int sz = 0;
      MaxHeap(int len) { heap = new Type[len]; }
      Type& operator[](size_t n) & { return heap[n]; }
      void push(Type x)
      {
          Type nu = sz;
          sz++;
          while (nu > 0)
          {
              int parent = (nu - 1) / 2;
              if (heap[parent] >= x) 
                  break;
              heap[nu] = heap[parent];
              nu = parent;
          }
          heap[nu] = x;
      }
      void pop()
      {
          Type x = heap[--sz];
          int nu = 0;
          while (nu * 2 + 1 < sz)
          {
              int a = nu * 2 + 1;
              int b = nu * 2 + 2;
              if (b < sz && heap[b] > heap[a]) 
                  a = b;
              if (heap[a] <= x) 
                  break;
              heap[nu] = heap[a];
              nu = a;
          }
          heap[nu] = x;
      }
      Type top() { return heap[0]; }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    MaxHeap<int> hp(MAX_N);
    string s;
    while(cin >> s)
    {
        if(s == "end") break;
        if(s == "insert") 
        {
            int x; cin >> x;
            hp.push(x);
        }
        else
        {
            cout << hp.top() << endl;
            hp.pop();
        }
    }
    return 0;
}




Measured memory_bytes: 7124
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string S;
    long long K;cin>>S>>K;
    for(long long i=0;i<K;i++){
        if(S[i]!='1'){
            cout<<S[i]<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();

		double h_angle = h * 30 + (m * 0.5);
		double m_angle = m * 6;

		double diff_angle = Math.abs(h_angle - m_angle);
		if (diff_angle == 180.0) {
			System.out.println(a + b);
		} else if (diff_angle == 0.0) {
			System.out.println(Math.abs(a - b));
		} else {
			double cosC = Math.cos(Math.toRadians(diff_angle));
			double length = Math.sqrt(a * a + b * b - 2 * a * b * cosC);
			System.out.println(length);
		}
	}

}


Measured memory_bytes: 35928
#include <bits/stdc++.h>
    #define pb push_back
    #define SZ(x) ((int)(x.size()))
    #define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
    #define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
    #define F first
    #define S second
    #define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
    #define TEST(x,i) ((x)&(1ll<<(i)))
    #define SET(x,i) ((x)|(1ll<<(i)))
    #define FLIP(x,i) ((x)^(1ll<<(i)))
    #define CLEAR(x,i) ((x)&~(1ll<<(i)))
     
    const double pi = 4 * atan(1);
    using namespace std;
    typedef long long ll;
     
    const ll MOD = 1000000007;
    const int MAXN = 200005;
     
    int main() {
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	
    	int n;
    	string s;
    	cin >> n >> s;
    	
    	map<char,int> cnt;
    	for(auto v : s) {
    		cnt[v]++;
    	}
    	
    	if (!cnt['R'] || !cnt['W']) {
    		cout << "0\n";
    		return 0;
    	}
    	
    	map<char,int> l;
    	for (int i = 0; i < cnt['R']; i++){
    		l[s[i]]++;
    	}
    	
    	map<char,int> r;
    	r['R'] = cnt['R'] - l['R'];
    	r['W'] = cnt['W'] - l['W'];
    	
    	int ans = r['R']+l['W'] - min(r['R'],l['W'] );
    	cout << ans << "\n";
     
    }

Measured memory_bytes: 3676
import math

factor    = list(map(int, input().split()))
factor[2] = factor[2] * 30 + factor[3] * 0.5
factor[3] = factor[3] * 6
degree    = abs(factor[2] - factor[3])
radian    = math.radians(degree)

answer    = math.sqrt((factor[0]**2 + factor[1]**2) - 2*(factor[0] * factor[1]) * math.cos(radian))
print(answer)

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N+2), L(N+2), R(N+2);
    for(int i=1; i<=N; i++) {
        cin >> A[i];
    }

    for(int i=1; i<=N; i++) {
        L[i] = max(L[i-1], A[i]);
    }

    for(int i=N; i>0; i--) {
        R[i] = max(R[i+1], A[i]);
    }

    for(int i=1; i<=N; i++) {
        cout << max(L[i-1], R[i+1]) << endl;
    }
    return 0;
}


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

#define int long long int
#define mp make_pair
using namespace std;

int n,k;
vector <int> v(102),w(102);
int dp[102][100002];
int fun(int pos , int curr)
{
    if(curr < 0){
        return -10000000000;
    }
    if(pos == n){
        return 0;
    }
    if(dp[pos][curr] != -1){
        return dp[pos][curr];
    }
    dp[pos][curr] = max(fun(pos + 1 , curr) ,v[pos] +  fun(pos + 1 , curr - w[pos]));
    return dp[pos][curr];
}

int32_t main() {
    scanf("%lld", &n);
    scanf("%lld", &k);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &w[i]);
        scanf("%lld", &v[i]);
    }
    for (int i = 0; i < 102; ++i) {
        for (int j = 0; j < 100002; ++j) {
            dp[i][j] = -1;
        }
    }
    int ans = fun(0 , k);
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 80000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
string s, t;
vector<int> v;
int ts, cnt, ans;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s; s += '&';
	for(char c: s){
		if(c != 'x'){
			t += c;
			v.push_back(cnt);
			cnt = 0;
		}else cnt++;
	}
	ts = (int)t.size();
	rep(i,ts/2){
		if(t[i] != t[ts-i-2]) return 0*puts("-1");
		ans += abs(v[i]-v[ts-i-1]);
	}
	cout << ans << '\n';
}

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

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  int ans=0;
  for(int i=1;i<=N;i++){
    int x=i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10;
    if(A<=x&&x<=B){
      ans+=i;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int gmin(int a,int b){return a<b?a:b;}
#define Ha 1000000007
long long fib[233]={1ll,1ll,2ll,3ll,5ll,8ll,13ll,21ll,34ll,55ll,89ll,144ll,233ll,377ll,610ll,987ll,1597ll,2584ll,4181ll,6765ll,10946ll,17711ll,28657ll,46368ll,75025ll,121393ll,196418ll,317811ll,514229ll,832040ll,1346269ll,2178309ll,3524578ll,5702887ll,9227465ll,14930352ll,24157817ll,39088169ll,63245986ll,102334155ll,165580141ll,267914296ll,433494437ll,701408733ll,1134903170ll,1836311903ll,2971215073ll,4807526976ll,7778742049ll,12586269025ll,20365011074ll,32951280099ll,53316291173ll,86267571272ll,139583862445ll,225851433717ll,365435296162ll,591286729879ll,956722026041ll,1548008755920ll,2504730781961ll,4052739537881ll,6557470319842ll,10610209857723ll,17167680177565ll,27777890035288ll,44945570212853ll,72723460248141ll,117669030460994ll,190392490709135ll,308061521170129ll,498454011879264ll,806515533049393ll,1304969544928657ll,2111485077978050ll,3416454622906707ll,5527939700884757ll,8944394323791464ll,14472334024676221ll,23416728348467685ll,37889062373143906ll,61305790721611591ll,99194853094755497ll,160500643816367088ll,259695496911122585ll,420196140727489673ll,679891637638612258ll,1100087778366101931ll};
long long a[6666];
int main()
{
	int T;
	for(scanf("%d",&T);T--;)
	{
		int i,j,r,c=0;
		long long n,m,x,y;
		scanf("%lld%lld",&n,&m);
		if(n<m)swap(n,m);
		if(m==1)
		{
			printf("1 %d\n",n%Ha);
			continue;
		}
		if(n==2&&m==2)
		{
			printf("1 4\n");
			continue;
		}
		for(i=1;fib[i];i++)if(fib[i]>n)break;
		for(j=1;fib[j];j++)if(fib[j]>m)break;
		i--;j--;
		r=gmin(i,j+1);
		a[0]=fib[r+1];
		a[1]=fib[r];
		//printf("%d (%lld %lld)\n",r,a[0],a[1]);
		for(i=2;i<r;i++)
		{
			if(i%4==0||i%4==1)a[i]=a[i-2]+fib[r-1-i];
			else a[i]=a[i-2]-fib[r-1-i];
		}
		//for(i=1;i<r;i++)printf("%d ",a[i]);
		a[0]=fib[r-1];
		for(i=1;i<r;i++)
		{
			if(a[i]>a[i-1])
			{
				x=a[i-1];
				y=a[i];
			}
			else
			{
				x=a[i];
				y=a[i-1];
			}
			if(x<=m&&y<=n)c=(c+(n-y)/x+1)%Ha;
		}
		for(i=1;i<r;i++)
		{
			if(a[i]>a[i-1])
			{
				x=a[i-1];
				y=a[i];
			}
			else
			{
				x=a[i];
				y=a[i-1];
			}
			if(x<=n&&y<=m)c=(c+(m-y)/x+1)%Ha;
		}
		printf("%d %d\n",r-1,c);
	}
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
map<string,int>mp;
int main() {
	int n;
	cin>>n;
	string str;
	int len;
	char r='9',l='9';
	
	while(n--){
		cin>>str;
		if(str[0]!=r&&r!='9'){
			cout<<"No";
			return 0;
		}
		if(!mp[str]){
			mp[str]++;
		}else{
			cout<<"No";
			return 0;
		}
		len=str.length();
		l=str[0];
		r=str[len-1];
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    ll C;
    cin >> C;
    vector<ll> x(n), v(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> v[i];
    ll s = 0;
    for (int i = 0; i < n; ++i)
        s += v[i];
    vector<ll> prawo2(n);
    vector<ll> lewo2(n);
    ll zysk = 0;
    for (int i = 0; i < n; ++i)
    {
        zysk += v[i];
        prawo2[i] = zysk - 2 * x[i];
        lewo2[i] = (s - zysk + v[i]) - 2 * (C - x[i]);
    }
    vector<ll> prawo1(n);
    vector<ll> lewo1(n);
    zysk = 0;
    for (int i = 0; i < n; ++i)
    {
        zysk += v[i];
        prawo1[i] = zysk - x[i];
        lewo1[i] = (s - zysk + v[i]) - (C - x[i]);
    }
    ll odp = 0;
    multiset<ll> S;
    for (int i = 0; i < n; ++i)
        S.insert(-prawo1[i]);
    for (int i = n - 1; i >= 0; --i)
    {
        S.erase(S.find(-prawo1[i]));
        if (S.size() == 0)
            break;
        ll x = -(*S.begin());
        odp = max(odp, lewo2[i] + x);
    }
    S.clear();
    for (int i = 0; i < n; ++i)
        S.insert(-lewo1[i]);
    for (int i = 0; i < n; ++i)
    {
        S.erase(S.find(-lewo1[i]));
        if (S.size() == 0)
            break;
        ll x = -(*S.begin());
        odp = max(odp, prawo2[i] + x);
    }
    for (int i = 0; i < n; ++i)
    {
        odp = max(odp, prawo1[i]);
        odp = max(odp, lewo1[i]);
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 9600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ull INF = 1e18;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ull> a(n);
  rep(i,n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i,n) {
    // if (ans * a[i] > INF) {
    //if (ans > INF) {
    if (ans > (INF / a[i])) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];

    // cout << ans << endl;
    if (ans > INF) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


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

//#define int long long
#define ll int long long
//#define REP(i,n) for(int i=0;i<n;i++)
//#define ALL(vec) (vec).begin(),(vec).end()
//#print_double(d) printf("%.9f\n", d)
/*
int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
*/

//const int INF = numeric_limits<int>::max();
/*
const int INF = 1e17;
struct edge {int to,cost;};
typedef pair<int,int> P;
vector<int> dijkstra(int s,vector<vector<edge>>&G){
    vector<int> d(G.size(),INF);
    priority_queue<P,vector<P>,greater<P>> que;
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(edge e : G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}
*/

signed main(){
    int n;
    string s;
    cin>>n>>s;
    string left=s.substr(0,n);
    string right=s.substr(n);
    reverse(right.begin(),right.end());
    
    // pair が怪しかったので string を "," でつないだ
    unordered_map<string, int> mp;
    
    // 2^n-1 から 0までループ
    for(int bit=1<<n;bit--;){
        string red,blue;
        for(int i=0;i<n;i++){
            if(bit&(1<<i))red+=left[i];
            else blue+=left[i];
        }
        if(mp.find(red+","+blue)==mp.end())
            mp[red+","+blue]=1;
        else
            mp[red+","+blue]++;
    }
    ll ans=0;
    for(int bit=1<<n;bit--;){
        string red,blue;
        for(int i=0;i<n;i++){
            if(bit&(1<<i))red+=right[i];
            else blue+=right[i];
        }
        if(mp.find(red+","+blue)!=mp.end())
            ans+=mp[red+","+blue];
    }
    cout<<ans<<endl;
}


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

int main()
{
  int a[3];
  rep(i,3){
    cin >> a[i];
  }

  sort(a, a + 3);
  cout << (a[2] - a[1]) + (a[1] - a[0]) << endl;
  return 0;
}


Measured memory_bytes: 3588
// ?????¬???????????¬??????

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// ??????????????????????????? (????????????????????°??????????????????????¬?????????¶????????????????????????????????¢)
// ?????????????????????????????????????????????????????????
// ?????????????°?????????¨??? 1 ????????????
// -> ?????????????????? (??°?????????????????????????????? 1 ??????????????????????????????) ??????????????????
//    ??°??????????????¢????????????????????????????????????????????°?????¨????????????????¬???°?????¶??°??§?????????
//    ?????£???????¬???°????\???°??§??????????????? 2 ????????????????????? (?????????????????°??????????????????????????????)
//    ?????¬??????????????°???????????°??????????????¬??????????????°?????? bit DP ?????¨?????????
//    ????????????????????°???????????¨???????????????????????? + ?????¬??????????????°????????? ??¨?????????

// (to, cost)
vector<pii> G[20];
int deg[20], dist[20][20], w[20][20], dp[1 << 15];

void solve() {
    int total = 0;
    int V, E; cin >> V >> E;
    rep(i,0,V) rep(j,0,V) {
        if(i == j) dist[i][j] = 0;
        else dist[i][j] = INF;
    }
    rep(i,0,E) {
        int s, t, d; cin >> s >> t >> d;
        G[s].push_back(pii(t, d));
        G[t].push_back(pii(s, d));
        chmin(dist[s][t], d);
        chmin(dist[t][s], d);
        total += d;
        deg[s]++; deg[t]++;
    }

    vector<int> odds;
    rep(i,0,V) if(deg[i] % 2) odds.push_back(i);
    int M = odds.size();

    rep(k,0,V) rep(i,0,V) rep(j,0,V) {
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
    rep(i,0,M) rep(j,0,M) w[i][j] = dist[ odds[i] ][ odds[j] ];

    rep(i,1,1<<M) dp[i] = INF;
    rep(bit,0,1<<M) rep(i,0,M) rep(j,i+1,M) {
        if((bit >> i & 1) || (bit >> j & 1)) continue;
        chmin(dp[bit | (1 << i) | (1 << j)], dp[bit] + w[i][j]);
    }
    cout << total + dp[(1<<M)-1] << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3220
main :: IO ()
main = do
    line <- getLine
    putStrLn $ toDateTime (read line :: Int)

toDateTime :: Int -> String
toDateTime n =
    let
        hour =  n `div` (60 * 60)
        min  = (n `mod` (60 * 60)) `div` 60
        sec  = (n `mod` (60 * 60)) `mod` 60
    in (show hour) ++ ":" ++ (show min) ++ ":" ++ (show sec)

Measured memory_bytes: 3600
import math
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for _ in range(n):
  x[_], y[_] = list(map(int, input().split()))

sum_distance = 0

for i in range(n):
  for j in range(n):
    sum_distance += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    
print(sum_distance/n)

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func splitElement() []int {
	var list []int
	sc.Scan()
	for _, v := range strings.Split(sc.Text(), " ") {
		num, _ := strconv.Atoi(v)
		list = append(list, num)
	}
	return list
}

func main() {
	A := splitElement()
	if A[0] == A[1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int a,b,c;
    cin >> a >> b >> c;
    cout << ((a+b)>=(c-1)?b+c:a+b+b+1) << endl;
	return 0;
}


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

using namespace std;

int main() {
 
  int n;
  cin >> n;
  int v = n % 10;
  if (v == 0 || v == 1 || v == 6 || v == 8)
    cout << "pon";
  else if (v == 3)
    cout << "bon";
  else 
    cout << "hon";
  
}

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

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

    int K, A, B;
    cin >> K >> A >> B;
    int L = K;
    while (L <= B) {
        if (A <= L && L <= B) {
            cout << "OK" << endl;
            return 0;
        }
        L += K;
    }
    cout << "NG" << endl;

    return 0;
}

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

int main(){
	string s,t;
	cin >> s >> t;
	
	vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));
	
	rep(i,dp.size()-1){
		rep(j,dp[0].size()-1){
			if(s[i] == t[j]){
				dp[i+1][j+1] = dp[i][j] + 1;
			}
			else{
				dp[i+1][j+1] = max( dp[i+1][j], dp[i][j+1] );
			}
		}
	}
	
	string res;
	int i = s.size(), j = t.size();
	while(i >= 1 && j >= 1){
		if(dp[i-1][j] == dp[i][j]) i--;
		else if(dp[i][j-1] == dp[i][j]) j--;
		else{
			res += s[i-1];
			i--; j--;
		}
	}
	reverse(res.begin(), res.end());
	cout << res << endl;
	return 0;
}

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

const int N=3005;
int dp[N][N][5];
int a[N][N];
int row,col,k;

int solve(int r,int c,int sel)
{
    if(r>row or c>col)return 0;
    if(r==row and c==col)
    {
        if(sel==3)
        return 0;
        return a[row][col];
    }
    
    int &ans=dp[r][c][sel];
    if(ans!=-1)return ans;
    ans=0;
    
    int op1=0,op2=0,op3=0,op4=0;
    op1=solve(r+1,c,0);
    op2=solve(r,c+1,sel);
    
    if(sel!=3)//
    {
        op3=a[r][c]+solve(r,c+1,sel+1);
        op4=a[r][c]+solve(r+1,c,0);
    }
    
    return ans=max({op1,op2,op3,op4});
    
    
}


void solve()
{
    cin>>row>>col>>k;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<k;i++)
    {
        int r1,c1,val;
        cin>>r1>>c1>>val;
        
        a[r1][c1]=val;
    }
    
    int ans=solve(1,1,0);
    
    cout<<ans<<'\n';
    
    
}

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

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

int d, g;
vector<int> pv, cv;

int main(){
  	cin >> d >> g;
	pv = cv = vector<int>(d);
  	for(int i = 0; i < d; i++){
    	cin >> pv.at(i) >> cv.at(i);
    }

  	int mct = 1000000;
  	for(int i = 0; i < (1 << d); i++){
    	bitset<10> bt(i);
      	int pnt = 0;
      	int ct = 0;
      	for(int j = 0; j < d; j++){
        	if(bt.test(j)){
            	ct += pv.at(j);
              	pnt += 100*(j+1)*pv.at(j)+cv.at(j);
            }
        }
      	
      	for(int j = d - 1; j >= 0; j--){
          	if(!bt.test(j)){
          		for(int k = 0; k < pv.at(j) - 1; k++){
            		if(pnt < g){pnt += 100*(j+1);	ct++;}
              		else break;
            	}
            }
        }
      	
      	if(g <= pnt) mct = min(mct,ct);
      	
    }
	
    cout << mct << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int dp[int(1e5+2)] , x[int(1e5+2)] ;
int main() {
	int n , k ;
	cin >> n >> k ;
	for ( int i = 0 ; i < n ; i++ ) {
		cin >> x[i] ;
		if ( i == 0 ) continue ;
		int mn = 1e9 ;
		for ( int j = max(0,i-k) ; j < i ; j++ ) {
			mn = min(mn,abs(x[i]-x[j])+dp[j]) ;
		}
		dp[i] = mn ;
	}
	cout << dp[n-1] ;
	return 0;
}

Measured memory_bytes: 4368
#include<iostream>

using ull = unsigned long long;
using namespace std;

#define B1 100000007
#define B2 1000000007

bool rolling_hash(string const &S, int t_start, int m){
    int s_start = t_start + m;

    // B^mを用意する
    ull pow_B_m_1 = 1, pow_B_m_2 = 1;
    for(int k = 0; k < m; k++){
        pow_B_m_1 *= B1, pow_B_m_2 *= B2;
    }

    // sとtの先頭m文字のハッシュ値sh,thを計算
    ull sh1 = 0, sh2 = 0, th1 = 0, th2 = 0;
    for(int k = 0; k < m; k++){
        th1 = th1 * B1 + S[t_start + k], th2 = th2 * B2 + S[t_start + k];
        sh1 = sh1 * B1 + S[s_start + k], sh2 = sh2 * B2 + S[s_start + k];
    }

    // sをずらしてハッシュ値を更新
    for(int k = 0; s_start + m + k < S.length(); k++){
        if(sh1 == th1 && sh2 == th2) return true;
        sh1 = sh1 * B1 + S[s_start + m + k] - S[s_start + k] * pow_B_m_1;
        sh2 = sh2 * B2 + S[s_start + m + k] - S[s_start + k] * pow_B_m_2;
    }
  	if(sh1 == th1 && sh2 == th2) return true;
    return false;
}

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

    // 一致する最大文字数を２分探索
    int ng = n+1, ok = 0, mid;
    while(ng - ok > 1){
        mid = (ng + ok) / 2;
        bool mached = false;
        // Sのi文字目をtの先頭として,t = S[i:i+mid], s = S[i+mid:n]
        for(int i = 0; i <= n - mid*2; i++){
            if(rolling_hash(S, i, mid)){
                mached = true;
                break;
            }
        }
        if(mached) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> s(n,1);
	int x;
	for (int i = 2; i <= n; i++) {
		//cout << i << endl;
		x = -1;
		while (1) {
			x += i;
			if (x >= n)
				break;
			s[x]++;
		}
	}

	long long sum = 0;
	for(int i=1;i<=n;i++){
		sum +=(long long) i * s[i - 1];
	}


	/*rep(i, n)
		cout << s[i] << endl;*/
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 42244
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define N 100009
ll a[3][N],dp[N][4],n;
ll sol(ll pos,ll last)
{
    if(dp[pos][last]!=-1)
    {
        return dp[pos][last];
    }
    if(pos==n)
    {
        return 0;
    }
    ll res  =0;

    for(ll i=0;i<=2;i++)
    {
        if(i!=last)
        {
            res = max(res,sol(pos+1,i)+a[i][pos]);
        }
    }
    return dp[pos][last] = res;
}
int main()
{
    ll i,t,k,j,x=0,y=0,m;
    cin>>n;
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[j][i];
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<sol(0,3)<<endl;
    return 0;
}



Measured memory_bytes: 11904
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		int n = str.length();
		
		boolean flag = true;
		StringBuffer sb = new StringBuffer(str);
		String dst = sb.reverse().toString();
		if(!dst.equals(str))flag = false;
		
		int x =(n-1)/2;
		int y =(n+3)/2;

		sb = new StringBuffer(str.substring(0, x));
		dst = sb.reverse().toString();
		if(!dst.equals(str.substring(0, x)))flag = false;

		sb = new StringBuffer(str.substring(y - 1, n));
		dst = sb.reverse().toString();
		if(!dst.equals(str.substring(y - 1, n)))flag = false;
		
		System.out.println(((flag)?"Yes":"No"));
	}
}

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

using ll = long long;

int main(void)
{
    ll k;
    string s;
    cin >> k;
    cin >> s;
    if(s.length() <= k)
    {
        cout << s << endl;
    }
    else
    {
        for(int i=0;i<k;i++)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    
    return 0;
}


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

// Macros and Constants
#define ll long long
const ll mod=1000000007LL;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     ifstream cin("practice/input.txt");
    //     ofstream cout("practice/output.txt");
    // #endif

    int A, B;
    cin >> A >> B;

    for (int i = 1; i <= 10001; i++) {
        int a = i*(0.08), b = i*(0.1);
        if (a == A and b == B) {
            cout << i;
            return 0;
        }
    }
    
    cout << "-1";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
res = n
for i in range(n+1):
    cc=0
    t=i
    while(t>0):
        cc+=t%6
        t = int(t/6)
    t = n-i
    while(t>0):
        cc+=t%9
        t = int(t/9)
    if res > cc:
        res =cc
print(res)


Measured memory_bytes: 3060