akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

}

void calculate(){
    int N;
    Input::input(N);
    vector<int> a(N);
    Input::inputVec(a);
    set<int> _set;
    rep(i,N) _set.insert(a[i]);
    cout << _set.size() << '\n';
}

int main(int,char**){
    calculate();    
}




Measured memory_bytes: 256
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
from functools import reduce
def gcd_list(numbers):
   return reduce(gcd, numbers)
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for x in range(1,k+1):
            ans+=gcd_list([i,j,x])
print(ans)

Measured memory_bytes: 70280
s = input()

for i, c in enumerate(s):
    if i % 2 == 0:
        if c not in {'R', 'U', 'D'}:
            print('No')
            break
    else:
        if c not in {'L', 'U', 'D'}:
            print('No')
            break
else:
    print('Yes')

Measured memory_bytes: 3060
#include <stdio.h>
#include <limits.h>

#define WHITE 0
#define BLACK 1

int main(){

  int n, G[100][100], d[100], pi[100], color[100];
  int i, j, u, k, v, c, mincost, sum = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++) for(j = 0; j < n; j++) G[i][j] = -1;

  for(i = 0; i < n; i++){
    d[i] = INT_MAX;
    pi[i] = 0;
    color[i] = WHITE;
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d%d", &v, &c);
      G[u][v] = c;
    }
  }

  d[0] = 0;

  while(1){
    mincost = INT_MAX;
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INT_MAX) break;
    color[u] = BLACK;
    for(i = 0; i < n; i++){
      if(G[u][i] != -1 && color[i] != BLACK && d[u] + G[u][i] < d[i]){
	pi[i] = u;
	d[i] = G[u][i];
	d[i] += d[pi[i]];
      }
    }
  }

  for(i = 0; i < n; i++) printf("%d %d\n", i, d[i]);
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>

using namespace std;

int main(){
  vector<vector<long long>> anss;
  vector<long long> soin = {6,8};
  for(long long i = 2 ; i*7 < 60000 ;i++){
      int flag = 0;
      for(long long j = 0; soin[j] < i*7-1 && j < soin.size();j++ ){
        if((i*7-1)%soin[j] == 0) flag = 1;
      }
      if(!flag){
        soin.push_back(i*7-1);
      }
      flag = 0;
      for(long long j = 0; soin[j] < i*7+1 && j < soin.size();j++ ){
        if((i*7+1)%soin[j] == 0) flag = 1;
      }
      if(!flag){
        soin.push_back(i*7+1);
      }
    }
  vector<long long> sub;
  long long N;
  cin >> N;
  while(N != 1){
    sub.push_back(N);
    vector<long long>ans;
    for(int i = 0; i < soin.size() && soin[i] <= N/6; i++){
      if(N % soin[i] == 0){
        ans.push_back(soin[i]);
      }
    }
    if(ans.size()) anss.push_back(ans);
    else anss.push_back({N});
    cin >> N;
  }
  for(int i = 0; i < sub.size(); i++){
    cout << sub[i] << ':';
    for(int j = 0 ; j < anss[i].size(); j++){
      cout << ' ' << anss[i][j];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3208
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
a = list(map(lambda x:int(x)*(-1), input().split()))

heapify(a)
while m > 0:
    m -= 1
    heappush(a, (-1)*(-heappop(a)//2))
print(-sum(a))

Measured memory_bytes: 21304
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<queue>
#define ll long long
#define inf INT_MAX
ll int d[1010][1010];
char a[1010][1010];
ll int solve(ll int h,ll int w,ll int i,ll int j)
{
	ll int res=0;
	if(i==h&&j==w)
	{
		return 1;
	}
	
	else
	{
		if(d[i][j]!=0)
		return d[i][j];
		else
		{
		if(a[i][j]=='#')
		  return 0;
		else
		{
			res=res+ (solve(h,w,i+1,j)+solve(h,w,i,j+1));
		}
	}
	d[i][j]=res;
	return d[i][j];
}
}
#define mod 1000000007
main()
{
   ll int  m,n;
   cin>>m>>n;
   memset(a,'#',sizeof(a));
   //cout<<a[1000][99]<<endl;;
   memset(d,0,sizeof(0));
   //cout<<m<<endl;
   for(int i=1;i<=m;i++)
   {
   	for(int j=1;j<=n;j++)
   	{
   		cin>>a[i][j];
	   }
   }
   ll int s=0;
   for(int i=1;i<=n;i++)
   {
   	if(a[1][i]=='#'||s==1)
   	{
   		d[1][i]=0;
   		s=1;
   	
	   }
	   else
	   d[1][i]=1;
   }
   s=0;
   for(int i=1;i<=n;i++)
   {
   	if(a[i][1]=='#'||s==1)
   	{
   		d[i][1]=0;
   		s=1;}
	   else
	   d[i][1]=1;}
	  for(int i=2;i<=m;i++)
	  {
	  	for(int j=2;j<=n;j++)
	  	{
	  		if(a[i][j]=='#')
	  		d[i][j]=0;
	  		else
	  		d[i][j]=(d[i-1][j]+d[i][j-1])%mod;
		  }
	   } 
   cout<<(d[m][n]%mod)<<endl;
  // ll int p=solve(m,n,1,1);
   /*for(int i=1;i<=m;i++)
   {
   	for(int j=1;j<=n;j++)
   	cout<<d[i][j]<<" ";
   	cout<<endl;
   }*/
   //cout<<d[m][n]<<endl;
   //cout<<p<<endl;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
int d,k,L,i,j,ten[15],a[25];
int s[25],mx,f[25];ll ans,an;
void dfs(int x,ll now){
	if (L-x>=k-1&&abs(now)>=10) return;
	if (now<=-10) return;
	int i;
	if (x>mx){
		an=a[s[1]+9]-(s[1]<=0);
		if (L&1) an*=10-(L==1);
		s[L]=-s[1];
		fo(i,2,mx) an*=a[s[i]+9],s[L-i+1]=-s[i];
		ll p=0;
		fd(i,L,1){
			p=p*10+s[i];
			if (p>d) return;
		}if (p==d) ans+=an;
		return;
	}
	fo(i,-9,9) s[x]=i,dfs(x+1,now*10-i);
}
int main(){
	ten[0]=1;
	fo(i,1,9) ten[i]=ten[i-1]*10;
	scanf("%d",&d);
	fo(i,1,9) if (d<ten[i]) break;
	k=i+1;
	fo(i,0,9)
	fo(j,0,9) a[i-j+9]++;
	fo(L,2,k<<1){
		mx=L>>1;
		memset(s,0,sizeof(s));
		dfs(1,0);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)

input=sys.stdin.readline

n,m=map(int,input().split())
G=[[False]*n for _ in range(n)]
used=[False]*n

def dfs(now,depth):
    if used[now]:
        return 0
    if n==depth:
        return 1
    used[now]=True
    ans=0
    for i in range(n):
        if G[now][i]:
            ans+=dfs(i,depth+1)
    used[now]=False
    return ans

for _ in range(m):
    a,b=map(int,input().split())
    G[a-1][b-1]=True
    G[b-1][a-1]=True

print(dfs(0,1))

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

int main(void) {
    ll a,b,x;cin>>a>>b>>x;
    ll b_number = b / x;
    ll a_number = a / x;
    if (a % x == 0) cout << b_number - a_number + 1 << endl;
    else cout << b_number - a_number << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

const ll MOD = (ll)pow(10,9)+7;

int main(){
  
  ll n;
  cin >> n;
  
  ll ans = 0;
  
  ll a = 1;
  ll b = 1;
  ll c = 1;
  
  while(n>0){
    a *= 10;
    b *= 9;
    c *= 8;
    a %= MOD;
    b %= MOD;
    c %= MOD;
    n --;
  }
  ans = (a + c)%MOD;
  ans = ((ans - 2*b)%MOD + MOD)%MOD;
  
  cout << ans << endl;
}


Measured memory_bytes: 3628
hight = []
width = []
num = 0

while True:
    H,W = list(map(int,input().split()))
    if H==0 and W==0:
      break
    else:
      hight.append(H)
      width.append(W)
      num += 1

for i in range(num):
    for j in range(1,hight[i]+1):
      for k in range(1,width[i]+1):
        if (j+k)%2==0:
          print("#",end="")
        else:
          print(".",end="")
      print("")
    print("")


Measured memory_bytes: 7012
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) ); 
// 大文字65-90(-32)
// 小文字97-122(+32)

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n,r; cin >> n >> r;
  if(n>=10){
    cout << r << endl;
  }else{
    cout << r+100*(10-n) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

L = {}
R = {}
for i, a in enumerate(A):
    x = i + 1 + a
    L[x] = L[x] + 1 if x in L else 1

    x = i + 1 - a
    R[x] = R[x] + 1 if x in R else 1

# print(L, R)

ans = 0
for x in L.keys():
    ans += L[x] * (R[x] if x in R else 0)

print(ans)


Measured memory_bytes: 56568
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <array>
#include <numeric>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    print(min(A*N, B));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

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

	string s;
  	cin >> s;
  	int i, j, k;
  	bool flag = true;
  	for (i = 0; i < 2 && flag; i++) {
      for (j = 0; j < 2 && flag; j++) {
        for (k = 0; k < 2 && flag; k++) {
          int t = s[0] - '0';
          
          if (i == 0) t += s[1] - '0';
          else t -= s[1] - '0';
          
          if (j == 0) t += s[2] - '0';
          else t -= s[2] - '0';
          
          if (k == 0) t += s[3] - '0';
          else t -= s[3] - '0';
          
          if (t == 7) {
            cout << s[0]; if (i == 0) cout << '+'; else cout << '-';
  			cout << s[1]; if (j == 0) cout << '+'; else cout << '-';
  			cout << s[2]; if (k == 0) cout << '+'; else cout << '-';
  			cout << s[3] << "=" << t;
            
            flag = false;
          }
        }
      }
    }

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; i++)
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> v{istream_iterator<int>(cin),istream_iterator<int>()};
  
  int total = 0;
  rep(i,N)  total = total + v[i];
  cout << total - N <<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var K, S, ans int
	fmt.Scan(&K, &S)
	for x := 0; x <= K; x++ {
		for y := 0; y <= K; y++ {
			z := S - x - y
			if 0 <= z && z <= K {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;
  vector<ll> c(n), s(n), f(n);
  REP(i, n-1)
    cin >> c[i] >> s[i] >> f[i];

  REP(i, n){
    ll sum = 0;
    for(int j = i; j < n-1; j++){
      if(sum < s[j])
        sum = s[j];
      else if(sum  % f[j] == 0)
        ;
      else
        sum += f[j] - sum % f[j];
      sum += c[j];
    }
    cout << sum << "\n";
  }
  
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()

	ryuka := 0
	older := 1
	oldest := 2

	if n == 1 {
		fmt.Println(older)
		return
	}

	for i := 3; i <= n+1; i++ {
		ryuka = older + oldest
		oldest = older
		older = ryuka
	}

	fmt.Println(ryuka)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

typedef long long ll;

const int MAXN = 50;
const int MOD = 1e9 + 7;

struct matrix{

	ll mat[MAXN][MAXN];

	matrix(int idd = 0){
		for(int i = 0;i<MAXN;i++){
			for(int j = 0;j<MAXN;j++){
				mat[i][j] = (idd) ? (i == j) : (0);
			}
		}
	}

	matrix operator*(const matrix& other)const{
		matrix ans;
		for(int i = 0;i<MAXN;i++){
			for(int j = 0;j<MAXN;j++){
				for(int k = 0;k<MAXN;k++){
					ans.mat[i][j] += mat[i][k]*other.mat[k][j];
					if(ans.mat[i][j] > MOD) ans.mat[i][j] %= MOD;
				}
			}
		}
		return ans;
	}

};

matrix exponentiation(matrix base, ll K){

	matrix ans(1);

	for(int i = 0;(1LL << i) <= K;i++){
		if((1LL << i) & K) ans = ans*base;
		base = base*base;
	}

	return ans;

}

int main(){

	matrix base;
	int N;
	ll K;
	cin >> N >> K;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++) cin >> base.mat[i][j];
	}

	matrix ans = exponentiation(base,K);
	ll paths = 0;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			paths = (paths + ans.mat[i][j]) % MOD;
		}
	}

	cout << paths << endl;

	return 0;

}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll l,r,d;
    cin>>l>>r>>d;
    int count = 0;
    for(ll i = l;i<=r;i++){
        if(i%d == 0){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

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

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	
	if(a % 3 == 0){
		printf("Possible\n");
		exit(0);
	}else if(b % 3 == 0){
		printf("Possible\n");
		exit(0);
	}else if((a + b) % 3 == 0){
		printf("Possible\n");
		exit(0);
	}else printf("Impossible\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<int, ll> mp;
	auto factrize = [&](int a) {
		for (int i = 2; i * i <= a; ++i) {
			while (a % i == 0) {
				a /= i;
				mp[i]++;
			}
		}
		if (a != 1) mp[a]++;
	};
	for (int i = 2; i <= n; ++i) {
		factrize(i);
	}
	ll ans = 1;
	for (auto c : mp) {
		ans *= (c.second + 1);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
  int K;
  string S, S2;
  char s;
  cin >> K >> S;
  
  if(S.size() > K)
  {
    for(int i = 0; i < K; i++)
    {
      s = S.at(i);
      S2 += s;
    }
    cout << S2 << "..." << endl;
  }
  else{cout << S << endl;}
}

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

int n;
int f[100][10];
int p[100][11];
int ans = INT_MIN;
int open[10];
int Count[100];

void dfs(int cnt) {
    if (cnt == 10) {
        // init and check
        bool brk = true;
        for (int i = 0; i < 10; i++) {
            if(open[i]) brk = false;
        }
        for (int i = 0; i < n; i++) {
            Count[i] = 0;
        }
        if (brk) return;
        // count
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                if (open[j] == 0) continue;
                if (f[i][j]) Count[i]++;
            }
        }
        // calc 
        int num = 0;
        for (int i = 0; i < n; i++) {
            num += p[i][Count[i]];
        }
        ans = max(ans, num);
    } else {
        open[cnt] = 0;
        dfs(cnt+1);
        open[cnt] = 1;
        dfs(cnt+1);
    }
}

signed main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 10; j++) {
            cin >> p[i][j];
        }
    }
    dfs(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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



int main() {
	int n, m, q;
	cin >> n >> m >> q;


	vector<vector<int>> con(q, vector<int>(4));
	for (int i = 0; i < q; i++) {
		
		cin >> con[i][0]>> con[i][1] >> con[i][2] >> con[i][3];
		con[i][0]--;
		con[i][1]--;
	}

	int ans = 0;
	for (int bi = 0; bi <= (1 << n + m - 1); bi++) {

		int cnt = 0;
		for (int i = 0; i < n + m - 1; i++) {
			if (((bi >> i) & 1) == 1) {
				cnt++;
			}
		}

		if (cnt != m - 1) {
			continue;
		}

		vector<int> seq;
		int num = 1;
		for (int i = 0; i < n + m - 1; i++) {
			if (((bi >> i) & 1) == 1) {
				num++;
			}
			else {
				seq.emplace_back(num);
			}
		}

		int score = 0;
		for (int i = 0; i < q; i++) {
			if (seq[con[i][1]] - seq[con[i][0]] == con[i][2]) {
				score += con[i][3];
			}
		}

		ans = max(ans, score);
	}

	cout << ans;
}

Measured memory_bytes: 3084
N, = map(int, raw_input().split())
x = [0]*N
y = [0]*N
h = [0]*N
for i in range(N):
  x[i], y[i], h[i] = map(int, raw_input().split())
for cx in range(101):
  for cy in range(101):
    for i in range(N):
      if h[i]!=0:
        H = h[i]+abs(x[i]-cx)+abs(y[i]-cy)
        break
    hit=True
    for i in range(N):
      ch = max(0, H-abs(x[i]-cx)-abs(y[i]-cy))
      if ch!=h[i]:
        hit=False
        break
    if hit:
      print cx, cy, H

Measured memory_bytes: 2696
def main():
    N, M = map(int, input().split())
    cumsum = [0] * (N+1)
    for i in range(M):
        L, R = map(int, input().split())
        cumsum[L-1] += 1
        cumsum[R] -= 1
    for i in range(1, N+1):
        cumsum[i] = cumsum[i] + cumsum[i-1]
    ans = 0
    for i in range(N):
        if cumsum[i] == M:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int aa[501][501];

int main() {
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> aa[i][j];
    vector<pair<P, P>> ans;
    rep(i, h) {
        if (i%2==0) {
            rep(j, w) {
                if (j != w-1) {
                    if (aa[i][j]%2) {
                        P a(i, j), b(i, j+1);
                        ans.emplace_back(a, b);
                        aa[i][j+1]++;
                    }
                }
                else {
                    if (aa[i][j]%2 and i+1<h) {
                        P a(i, j), b(i+1, j);
                        aa[i+1][j]++;
                        ans.emplace_back(a, b);
                    }
                }
            }
        }
        else {
            for (int j=w-1; j>=0; --j) {
                if (j != 0) {
                    if (aa[i][j]%2) {
                        P a(i, j), b(i, j-1);
                        ans.emplace_back(a, b);
                        aa[i][j-1]++;
                    }
                }
                else {
                    if (aa[i][j]%2 and i+1<h) {
                        P a(i, j), b(i+1, j);
                        aa[i+1][j]++;
                        ans.emplace_back(a, b);
                    }
                }
            }
        }
    }

    cout << ans.size() << endl;
    for (auto& t : ans) {
        P a = t.first, b = t.second;
        cout << a.first+1 << ' ' << a.second+1 << ' ' << b.first+1 << ' ' << b.second+1 << endl;
    }
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm> 
#include<vector>
#include<map>
/*freopen("input.txt","r",stdin);
  	freopen("output.txt","w",stdout);
	 */
using namespace std;
int main()
{

	long long int n,i,s=0;
	cin>>n>>i;
	cout<<n*i;
}
	


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		double c = (double)(a+b)/2;
		//System.out.println(c);
		double syosuC = c-(int)c;
		int ans=0;
		if(syosuC>0) {
			ans = (int)c+1;
		}else {
			ans = (int)c;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, input().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def main():
    N, K = read_ints()

    dp = [[-10 for _ in range(K + 1)] for _ in range(N + 1)]

    dp[0] = [0] * (K + 1)
    for i in range(N + 1):
        dp[i][0] = 0

    for i in range(N):
        w, v = read_ints()
        for sum_w in range(K + 1):
            if sum_w - w < 0:
                dp[i + 1][sum_w] = dp[i][sum_w]
            else:
                dp[i + 1][sum_w] = max(
                    dp[i][sum_w],
                    dp[i][sum_w - w] + v)
    print(dp[-1][-1])


main()

# pythonでもpypyでもTLE


Measured memory_bytes: 217372
import math
a, b, h, m = map(int, input().split())

H = 360*(h/12+m/(60*12))
M = 360*m/60
HM = math.radians(abs(H-M))
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(HM))

print(ans)

Measured memory_bytes: 9384
#include<stdio.h>

void change(int*,int*);

int main(){
	int x=0,y=0,z=0;
	scanf("%d %d %d",&x,&y,&z);
	if(x>y){
		change(&x,&y);
	}
	if(x>z){
		change(&x,&z);
	}
	if(y>z){
		change(&y,&z);
	}
	printf("%d %d %d\n",x,y,z);
	return 0;
}

void change(int *a, int *b){
	int tmp=0;
	tmp=*a;
	*a=*b;
	*b=tmp;
}



Measured memory_bytes: 2760
N, M = map(int, input().split())
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())

ans = [0] * N
for i in range(M):
    ans[ A[i] - 1 ] += 1
    ans[ B[i] - 1 ] += 1

for i in range(N):
    print(ans[i])


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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

const int N = 100000;
int st[N + 5], to[(N << 1) + 5], nxt[(N << 1) + 5], e = 1;

inline void addedge(int u, int v) {
    to[++ e] = v; nxt[e] = st[u]; st[u] = e;
    to[++ e] = u; nxt[e] = st[v]; st[v] = e;
}

std::multiset<int> s;
typedef std::multiset<int> :: iterator sit;

int LIM = N + 5;
int f[N + 5], g[N + 5];
void dfs(int u, int fa = 0) {
    f[u] = g[u] = 0;
    for(int i = st[u]; i; i = nxt[i]) {
        int v = to[i];
        if(v != fa) dfs(v, u), f[u] += f[v];
    }

    s.clear();
    for(int i = st[u]; i; i = nxt[i]) {
        int v = to[i];
        if(v != fa) s.insert(g[v] + 1); 
    }
    
    int ret = oo;

    while(s.size()) {
        int x = (*s.rbegin());
        sit it = s.upper_bound(LIM - x);

        ++ f[u];
        if(it == s.begin() || s.size() == 1) {
            if(x < LIM) {
                chkmin(ret, x);
                s.erase(s.find(*s.rbegin()));
            } else {
                s.erase(s.find(*s.rbegin()));
            }
        } else {
            -- it;
            s.erase(s.find(*it));
            s.erase(s.find(*s.rbegin()));
        }
    }
    if(ret != oo && u > 1) g[u] = ret, -- f[u];

}

int x, y, n;
int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    read(n);
    for(int i = 1; i < n; ++i) {
        read(x), read(y);
        addedge(x, y);
    }

    dfs(1);
    int A = f[1];

    int L = 1, R = n;
    while(L < R) {
        LIM = (L + R) >> 1;

        dfs(1);
        if(f[1] > A) L = LIM + 1; else R = LIM;
    }

    printf("%d %d\n", A, R);

    return 0;
}


Measured memory_bytes: 9600
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split())) 

ans = 0

for i in range(2**N):
    s = str(bin(i))
    condition = s[2:].zfill(N)

    # for j in range(M):
    #     switch_on = 0
    #     for k in ks[j][1:]:
    #         if condition[k-1] == "1":
    #             switch_on += 1
    #     if switch_on%2 != p[j]:
    #         break
    # else:
    #     ans += 1



    for j in range(M):
        cnt = 0
        for k in ks[j][1:]:
            if condition[k-1] == "1":
                cnt += 1
        if cnt%2 != p[j]:
            break
    else:
        ans += 1

print(ans)





Measured memory_bytes: 3064
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    cin>>s;
    int ans = 0;
    int n = s.size();
    for(int i=0;i<n;i++){
        ans += s[i] - '0';
        ans %= 9;
    }
    if(ans % 9 == 0)cout << "Yes\n";
    else cout << "No\n";
}   

Measured memory_bytes: 3728
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

struct uf{
  static const int MAXN=100005;
  int par[MAXN];
  int size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,MAXN) size[i]=1;
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int a,int b){
    a=root(a);b=root(b);
    if(a==b) return;
    if(size[a]<size[b]) swap(a,b);

    par[b]=a;
    size[a]+=size[b];
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};
uf u;
int n,m;
vector<int> g[100005];
int dep[100005];
int basis[100005];
void dfs(int v,int p,int d){
  dep[v]=d;
  for(auto to:g[v]){
    if(~dep[to]){
      int R=u.root(v);
      basis[R]=__gcd(basis[R],abs(dep[to]-dep[v])+1);
      continue;
    }
    dfs(to,v,d+1);
  }
}
int main(){
  cin>>n>>m;
  u.init();
  REP(i,m){
    int a,b;scanf("%d%d",&a,&b);--a;--b;
    g[a].pb(b);
    g[b].pb(a);
    u.unite(a,b);
  }
  memset(dep,-1,sizeof(dep));
  lint cnt[3]={0};
  lint size[3]={0};
  REP(i,n) if(u.root(i)==i){
    dfs(i,-1,0);
    assert(basis[i]<=2);
    ++cnt[basis[i]];
    size[basis[i]]+=u.size[i];
  }
  lint res=0;
  res+=size[0]*(lint)size[0];
  res+=size[0]*(lint)(size[1]+size[2])*2;
  res+=cnt[1]*cnt[1];
  res+=cnt[1]*cnt[2]*2;
  res+=cnt[2]*cnt[2]*2;
  cout<<res<<endl;
  return 0;
}





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

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

    string mark;
    int number;
    vector<vector<int>>cards(4,vector<int>(13, 0));

    for (int i = 0; i < n; i++) {
        cin >> mark >> number;
        if (mark == "S") {
            cards[0][number-1] = 1;
        }else if (mark == "H") {
            cards[1][number-1] = 1;
        }else if (mark == "C") {
            cards[2][number-1] = 1;
        }else if (mark == "D") {
            cards[3][number-1] = 1;
        }
    }

    for (int i = 0; i < cards.size(); i++) {
        for (int j = 0; j < cards[i].size(); j++) {
            if (cards[i][j] == 0) {
                if (i == 0) {
                    printf("S %d\n", j+1);
                }else if (i == 1) {
                    printf("H %d\n", j+1);
                }else if (i == 2) {
                    printf("C %d\n", j+1);
                }else if (i == 3) {
                    printf("D %d\n", j+1);
                } 
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3228
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)

bool ng;
string s;
map<string, int> variables;
vector<vector<int> > d;

vector<int> factor(int, int);
vector<int> term(int, int);
vector<int> formula(int, int);

vector<int> factor(int l, int r) {
	if(s[l] == '(')
		return formula(l + 1, r - 1);

	return d[variables[s.substr(l, r - l)]];
}

vector<int> term(int l, int r) {
	int cnt = 0;
	for(int i = r - 1; i >= l; --i) {
		if(s[i] == ')')
			++cnt;
		else if(s[i] == '(')
			--cnt;

		else if(s[i] == '*' || s[i] == '/') {
			if(cnt)
				continue;

			vector<int> vl = term(l, i);
			vector<int> vr = factor(i + 1, r);

			for(int j = 0; j < vl.size(); ++j)
				if(s[i] == '*')
					vl[j] += vr[j];
				else
					vl[j] -= vr[j];

			return vl;
		}
	}

	return factor(l, r);
}

vector<int> formula(int l, int r) {
	int cnt = 0;
	for(int i = r - 1; i >= l; --i) {
		if(s[i] == ')')
			++cnt;
		else if(s[i] == '(')
			--cnt;

		else if(s[i] == '+' || s[i] == '-') {
			if(cnt)
				continue;

			vector<int> vl = formula(l, i);
			vector<int> vr = term(i + 1, r);

			if(vl != vr)
				ng = true;

			return vl;
		}
	}

	return term(l, r);
}

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

	for(int n, m, p; cin >> n >> m >> p, n;) {
		map<string, int> deriveds;
		d.clear();
		d.resize(m, vector<int>(n));
		for(int i = 0, id = 0; i < m; ++i) {
			string in;
			cin >> in;
			deriveds[in] = id++;

			for(int j = 0; j < n; ++j)
				cin >> d[i][j];
		}

		cin >> s;

		variables.clear();
		for(int i = 0; i < p; ++i) {
			string v, D;
			cin >> v >> D;

			variables[v] = deriveds[D];
		}

		ng = false;
		vector<int> dimension = formula(0, s.size());

		if(ng) cout << "error" << endl;
		else {
			FOR(it, deriveds) {
				if(dimension == d[it->second]) {
					cout << it->first << endl;
					goto next;
				}
			}

			cout << "undefined" << endl;
		}

		next:;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int H,W;
  cin >> H>> W;
  
  vector<vector<char>> data(H+2,vector<char>(W+2,'#'));

  rep(i,H){
    rep(j,W){
      cin>>data.at(i+1).at(j+1);
    }
  }
  
  rep(i,H+2){
    rep(j,W+2){
      if(j == W+1){
        cout << data.at(i).at(j)<< endl;
      }
      else{
        cout << data.at(i).at(j);
      }
    }
  }
  
}

Measured memory_bytes: 764
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
# t=int(input())
t=1
for _ in range(t):
    # n,m=map(int,stdin.readline().split())
    a,b,h,m=map(int,stdin.readline().split())
    hang=(h)*30+(m*0.5)
    mang=m*6
    ang=abs(hang-mang)
    # if(ang>180):
    #     ang=ang-180
    # print(hang,mang,ang)
    ang=math.radians(ang)
    ans=math.sqrt((a*a)+(b*b)-(2*a*b*math.cos(ang)))
    print(ans)


Measured memory_bytes: 9804
from collections import deque
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n-1)]
tree = [[] for _ in range(n+1)]
color = [set([]) for _ in range(n+1)]
ans = {}
for a, b in ab:
    tree[a].append(b)

q = deque([1])
visited = {1}
while len(q) > 0:
    now = q.popleft()
    visited.add(now)
    cnt = 1
    for i in tree[now]:
        if i in visited:
            pass
        else:
            q.append(i)
            # non-used color decided
            if cnt in color[now]:
                cnt += 1
            color[i].add(cnt)
            ans[(now, i)] = cnt
            cnt += 1

print(max(ans.values()))
for i in ab:
    print(ans[i])




Measured memory_bytes: 67652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N;
    cin >> N;
    map<ll, ll, greater<ll>> A;
    rep(i, N)
    {
        ll a;
        cin >> a;
        A[a]++;
    }
    ll ans = 0;
    for (int i = 0; i < N, !A.empty(); i++)
    {
        ll a = A.begin()->first;
        A[a]--;
        if (A[a] == 0)
            A.erase(a);
        ll p = 1;
        while (p <= a)
        {
            p *= 2;
        }
        ll dif = p - a;
        if (A.count(dif) > 0)
        {
            ans++;
            A[p - a]--;
            if (A[p - a] == 0)
                A.erase(p - a);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 1e10;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
 

ll dp[11][110][1010];

int n, s;

int main(){
	while(cin>>n>>s){
		if(n == 0 && s == 0) break;
		ll ans = 0LL;
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= 100; j++){
				for(int k = 0; k <= s; k++){
					dp[i][j][k] = 0LL;
				}
			}
		}

		for(int i = 0; i <= min(s,100); i++) dp[1][i][s-i] = 1;
		for(int i = 2; i <= n; i++){//i??????
			for(int j = 0; j <= 100; j++){//i???????????°???j
				for(int k = 0; k < j; k++){//???????????????????????°k
					for(int l = j; l <= s; l++){//?????????l
						//if(dp[i-1][k][l] > 0){
							dp[i][j][l-j] += dp[i-1][k][l];
						//}
					}
				}
			}
		}

		for(int i = 0; i <= 100; i++){
			ans += dp[n][i][0];
		}

		cout<<ans<<endl;
	}
}

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

int main() {
  int N;
  cin >> N;
//  cout << N << endl;

  vector<char> c(N);
  for (int i=0; i<N; ++i) {
    cin >> c.at(i);
//    cout << c.at(i);
  }
  
  int cnt = 0;
  for (int i=0; i<N; ++i) {
    if (c.at(i) == 'R') cnt++;
  }

  int cnt2 = cnt;
  for (int i=0; i<cnt; ++i) {
    if (c.at(i) == 'R') cnt2--;
  }

  cout << cnt2 << endl;
  
  return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<string.h>

#define PY "YES\n"    // printf(PY);
#define PN "NO\n"     // printf(PN);


int main()
{
    int n, i, count=0, temp, a, b, pos_1, pos_2, flag=0;
    scanf("%d", &n);
    int arr[n+5];

    for(i=1; i<=n; i++)
        scanf("%d", &arr[i]);

    for(i=1; i<n; i++)
    {
        if(arr[i]>arr[i+1])
            count++;
    }
    if(count==1)
    {
        for(i=1; i<n; i++)
        {
            if(arr[i]>arr[i+1])
            {
                temp = arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
    }
    else if(count==2)
    {
        for(i=1; i<n; i++)
        {
            if(arr[i]>arr[i+1])
            {
                pos_1 = i;
                a = arr[pos_1];
                break;
            }
        }
        for(i=pos_1+1; i<n; i++)
        {
            if(arr[i]>arr[i+1])
            {
                pos_2 = i+1;
                b = arr[pos_2];
                break;
            }
        }
        arr[pos_1] = b;
        arr[pos_2] = a;
    }

    for(i=1; i<n; i++)
    {
        if(arr[i]>arr[i+1])
            flag++;
    }
    
    if(flag==0)
        printf(PY);
    else
        printf(PN);

    return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    int h = 100;
    int w = 100;
    string field[100][100];
    for(int j = 0; j < 100; j++){
        for(int i = 0; i < 50; i++){
            field[i][j] = '.';
        }
        for(int i = 50; i < 100; i++){
            field[i][j] = '#';
        }
    }
    for(int i = 1; i <= b - 1; i++){
        field[((i * 2 - 1) / 100) * 2][(i * 2 - 1) % 100] = '#';
    }
    for(int i = 1; i <= a - 1; i++){
        field[99 - (((i * 2 - 1) / 100) * 2)][99 - ((i * 2 - 1) % 100)] = '.';
    }
    cout << h << " " << w << endl;
    for(int i = 0; i <= 99; i++){
        for(int j = 0; j <= 99; j++){
            cout << field[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<20)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    int s,w;
    cin>>s>>w;
    if(s<=w)cout<<"unsafe";
    else cout<<"safe";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<map<int, int> > vm(N + 1);
	vm[1][1] = M; 
	int a, b;
	vector<int> sum(N, 0);
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		sum[0] += (a + 1) % b;
		//cerr << b - ((a + 1) % b) << endl;
		if (b - ((a + 1) % b) < N) {
			vm[b - ((a + 1) % b)][b] -= b;
		}
	}
	
	for (int i = 1; i < N; i++) {
		sum[i] = sum[i - 1];
		for (auto m = vm[i].begin(); m != vm[i].end(); m++) {
			//cerr << i << " " << (*m).first << " " << (*m).second << endl;
			sum[i] += (*m).second;
			if (i + (*m).first < N) {
				vm[i + (*m).first][(*m).first] += (*m).second;
			}
		}
		vm[i].clear();
	}
	for (int i = 0; i < N; i++) {
		cout << sum[i] << endl;
	}
}


Measured memory_bytes: 10584
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
//Cancel in interactive questions
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define got(container,num) get<num-1>(container)
using namespace std;
const int INF=LLONG_MAX/2;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;

main()
{
    IOS
    cin>>n;
    fu(i,1,10000)
    {
        int val=i*n;
        if(val%360==0)
        {
            out(i)
            exit(0);
        }
    }
    return 0;
}

Measured memory_bytes: 3652
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)
for i in range(N - 1):
    C[i], S[i], F[i] = ri_()
dp = [0] * N
for i in range(N):
    dp[i] = 0
    for j in range(i, N - 1):
        dp[j + 1] = C[j] + max(S[j], ceil(dp[j] / F[j]) * F[j])
    print(dp[N - 1])

Measured memory_bytes: 67944
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  long long k;
  cin >> k;
  int n = (int) s.size();
  if (s == string(n, s[0])) {
    cout << n * k / 2 << '\n';
  } else {
    int ans1 = 0;
    for (int i = 0; i + 1 < n; i++) {
      if (s[i % n] == s[(i + 1) % n]) {
        ++ans1;
        ++i;
      }
    }
    int ans2 = 0;
    for (int i = 0; i + 1 < 2 * n; i++) {
      if (s[i % n] == s[(i + 1) % n]) {
        ++ans2;
        ++i;
      }
    }
    cout << ans1 + (ans2 - ans1) * (k - 1) << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  long a, b, k;
  readf (" %d %d %d", &a, &b, &k);
  //a - Tak
  //b - Ao
  /*
     If Takahashi has one or more cookies, eat one of his cookies.
     Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.
     If they both have no cookies, do nothing.
  */
  long u = min (a, k);
  a -= u;
  k -= u;
  long v = min (b, k);
  b -= v;
  k -= v;
  writeln (a, ' ', b);
}



Measured memory_bytes: 256