akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    const double PI=3.14159265358979323846;
    double a,b,x;
    cin >> a >> b >> x;
    double s = x / a;
    //cerr << s << endl;
    double ans = 0;
    double la = 0;
    if ( s == a * b) {
        ans = 0;
    } else {
        if (s >= b * a / 2) {
            double ub = 2 * s / a - b;
            //cerr << "ub:" <<ub << endl;
            s -= a * ub;
            b -= ub;
            la = 2 * s / b;
        } else {
            la = 2 * s / b;
        }
        //cerr<<la << endl;
        auto r = atan2(b,la);
        //cerr << r << endl;
        ans = r * (180.0 / PI); 
    }
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;

  for (int i = 2; i <= n; i++) {
    int j = 2, k = i;
    while (k > 1) {
      if (k % j == 0) {
        k /= j;
        mp[j]++;
      } else {
        j++;
      }
    }
  }
  long long ans = 1;
  for (auto c : mp) {
    ans *= (c.second + 1);
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
loop {
    n, r = gets.split.map &:to_i
    break if n == 0
    a = (1..n).to_a.reverse
    r.times {
        p, c = gets.split.map &:to_i
        a = a[p-1..p-2+c] + (p > 1 ? a[0..p-2] : []) + a[p-1+c..n-1]
    }
    p a[0]
}

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

int main() {
  int N;
  cin >> N;
  
  int64_t ans = 1;
  for (int i = 1; i <= N; i++) {
    ans *= i;
    ans %= 1000000007;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max 1000000
char name[max][12];
int time[max];

int count = 0;
int head = 0;
int tail = 0;
int sumtime = 0;

void enque(int t,char ar[]){
  
  if(tail==max)tail = 0;
  time[tail] = t;
  int i=0;
  while(ar[i]){
    name[tail][i] =ar[i];
    i++;
  } 
  tail++;
  count++;
}

int deque(){
  count--;
  if(head==max)head = 0;
  return time[head++];
  
}


char ar1[12];
int ti;

int main(){
  
  int n,q; scanf("%d %d",&n,&q);
  char sp;
  for(int i=0;i<n;i++){
    
    scanf("%s",ar1);
    scanf("%d",&ti);
    
    if(ti<=q){
       sumtime += ti;
      printf("%s %d\n",ar1,sumtime);
    }
    else{
      sumtime += q;
      enque(ti-q,ar1);
    }
    
  }
 
  
  while(count>0){
    int temp = deque();
    int index = head-1;
        if(temp<=q){
       sumtime += temp;
      printf("%s %d\n",name[index],sumtime);
    }
    else{
      sumtime += q;
      enque(temp-q,name[index]);
    }
  }
  
  
  
  
  return 0;
}
  



Measured memory_bytes: 3864
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Map<String, Long> map = new HashMap<>();
    for (int i = 0; i < n; i++) {
        char[] s = sc.next().toCharArray();
        Arrays.sort(s);
        map.compute(String.valueOf(s), (key, value) -> value == null ? 1 : value + 1);
    }
    long ans = 0;
    for (long val : map.values()) {
        ans += val * (val - 1) / 2;
    }
    System.out.println(ans);
	}
}


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

int h[100001]={0};

signed main()
{
  int n,s=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      int x;
      cin>>x;
      h[x]++;
      s+=x;
  }
  int q;
  cin>>q;
  while(q--)
  {
      int a,b;
      cin>>a>>b;
      s+=(b-a)*h[a];
        h[b]+=h[a];
        h[a]=0;
       cout<<s<<endl; 
  }
  
}

Measured memory_bytes: 4272
def main():
    L, R = [int(n) for n in input().split()]
    if R - L >= 2019:
        L = 0
        R = 2018
    
    li = [[0]*2019 for i in range(2019)]
    for i in range(2019):
        for j in range(i, 2019):
            li[i][j] = (i * j) % 2019
    res = 2030
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            a, b = sorted([i%2019, j%2019])
            old = res
            res = min(res, li[a][b])
    print(res)
main()

Measured memory_bytes: 91508
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = INT_MAX / 2;
const ll      INFL= 1LL << 60;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

void _main() {
  int K, X;
  cin >> K >> X;

  int mi = X - (K-1);
  int ma = X + (K-1);
  rep(i, mi, ma+1) cout << i << (i==ma?"\n":" ");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   
    int a,b;
    cin >> a >> b;
    cout << max((a-2*b), 0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long[] num = new long[5];
		scn.nextLine();
		for (int i = 0; i < N; i++) {
			char[] buf = scn.nextLine().toCharArray();
			switch (buf[0]) {
			case 'M':
				num[0]++;
				break;
			case 'A':
				num[1]++;
				break;
			case 'R':
				num[2]++;
				break;
			case 'C':
				num[3]++;
				break;
			case 'H':
				num[4]++;
				break;
			default:
				break;
			}
		}
		long ans = 0;
		for(int i = 0;i < 3;i++) {
			for(int j = i+1;j < 4;j++) {
				for(int k = j+1;k < 5;k++) {
					ans += num[i] * num[j] * num[k];
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 91300
#include <stdio.h>
int main(void){
    int n,i;
    long long ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0) ans+=i;
    }
    printf("%lld",ans);
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int c = 0;
  rep(i,0,s.size()) if(s[i] == '2') c++;
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  cin >> n;
  string s;
  vl alpha(26);
  rep(_, n) {
    cin >> s;
    alpha[s[0]-'A']++;
  }
  
  string MARCH = "MARCH";
  vl cnt(5);
  rep(i, 5) cnt[i] = alpha[MARCH[i]-'A'];
  
  ll ans=0;
  vector<bool> choose3 = {0,0,1,1,1};
  do {
    ll num=1;
    rep(i, 5) if(choose3[i]) num *= cnt[i];
    ans += num;
  }while (next_permutation(all(choose3)));
  
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //repマクロ

int main() {

  int32_t N, ans=0;
  int32_t A[200];
  cin >> N ;
  rep(i, N){
    cin >>A[i];
    if(A[i]%2==1){
      cout << ans << endl;
      return 0;
    }
  }
  ans=1;
  while (1) {
    rep(i,N){
      A[i]/=2;
      if(A[i]%2==1){
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
    cout << ans << endl;
}

Measured memory_bytes: 3644
n=int(input())
sp_list=[]
for i in range(n):
	s,p=map(str,input().split())
	sp_list.append({'key': i+1,'city':s,'point':int(p)})
sp_list=sorted(sp_list,key = lambda x: (x['city'], -x['point']))
for i in sp_list:
	print(i['key'])

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

int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  if (A > B) cout << 0 << endl;
  else if (N == 1 && A < B) cout << 0 << endl;
  else if (N == 1 && A == B) cout << 1 << endl;
  else  cout << B * (N-2) - A *(N-2) + 1 << endl;
  
}


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

int main(){
	int n;
  	cin >> n;
  	vector<int> x(n);
  	rep(i, n) cin >> x[i];
  	
  	int ans = 1e9;
  	for(int i = 1; i <= 100; i++){
      	int p = 0;
      	rep(j, n) p += (x[j]-i)*(x[j]-i);
    	ans = min(ans, p);
    }
	
  	cout << ans << endl;
}

Measured memory_bytes: 3592
#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;
const LL LINF = 1e16;

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

  LL ans = 0;
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> student(N);
  vector<pair<int, int>> check(M);
  FOR(i, 0, N) { cin >> student[i].first >> student[i].second; }
  FOR(i, 0, M) { cin >> check[i].first >> check[i].second; }

  FOR(i, 0, N) {
    LL temp = LINF;
    ans = 1;

    FOR(j, 0, M) {
      LL distance = abs(student[i].first - check[j].first) +
                    abs(student[i].second - check[j].second);

      if (distance < temp) {
        ans = j + 1;
        temp = distance;
      }
    }

    cout << ans << '\n';
  }

  return 0;
}

Measured memory_bytes: 256
while 1:
	n,x=map(int,raw_input().split())
	c=0
	if(n==0 and x==0):
		break
	for i in range(1,n+1):
		for j in range(i+1,n+1):
			for k in range(j+1,n+1):
				if(i+j+k==x):
					c+=1
	print c

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 3e3;
const num inf = 0x3f3f3f3f3f3f3f3f;
int n, a[nsz + 5];
num dp[nsz + 5][nsz + 5][2];

num dfs(int l, int r, int me) {
    if (dp[l][r][me] != -inf)  return dp[l][r][me];
    if (l + r == n)  return 0;
    int i = l + 1, j = n - r;
    if (me == 0) {
        return dp[l][r][me] = max(dfs(l + 1, r, !me) + a[i], dfs(l, r + 1, !me) + a[j]);
    } else {
        return dp[l][r][me] = min(dfs(l + 1, r, !me) - a[i], dfs(l, r + 1, !me) - a[j]);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin >> n;
    cont (i, n) {
        cin >> a[i];
    }
    fill(dp[0][0], dp[0][0] + sizeof(dp) / sizeof(num), -inf);
    cout << dfs(0, 0, 0) << ln;
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll hash[200005] = {0};
    ll n;
    cin >> n;
    for(ll i = 0; i < n - 1; i++)
    {
        ll el;
        cin >> el;
            hash[el] += 1;
    }    
    for(ll i = 1; i <= n; i++)
    {
        cout << hash[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5204
import java.util.*;

public class Main {// Main
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
       String s = sc.next();
       String t =sc.next();
       t = t.substring(0 , t.length()-1);
       if(s.equals(t)) {
    	   System.out.println("Yes");
       }else {
    	   System.out.println("No");
       }
	}
}

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

bitset<100005> isPrime;
int a[100005];

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

	isPrime.set();
	isPrime[1] = 0;
	for (ll i = 2; i < 100005; i++)
	{
		if (isPrime[i])
		{
			for (ll x = i*i; x < 100005; x += i)
				isPrime[x] = 0;
		}
	}

	for (int i = 1; i <= 100000; i++)
	{
		a[i] = a[i-1];
		if (i & 1 and isPrime[i] and isPrime[(i+1)/2])
			a[i]++;
	}

	int q;
	cin >> q;
	while (q--)
	{
		int l, r;
		cin >> l >> r;
		cout << a[r]-a[l-1] << '\n';
	}
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int main(){
  int N,x,ans=0;
  string s;
  cin>>N>>s;

  for(int i=0;i<N;i++){
    if(s[i]=='I') x++;
    else x--;
    ans=max(ans,x);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#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 all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

ll gcd(ll x, ll y)
{
	ll r;

	if (x == 0 || y == 0)  // 引数チェック
	{
		fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	// ユーグリッドの互除法
	while ((r = x % y) != 0)  // yで割り切れるまでループ
	{
		x = y;
		y = r;
	}
	return y;
}

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

	ll a, b, c, d, n, m, ans = 0, ret = M;
	string s, t;
	bool flag = false;
	cin >> a >> b >> c;
	ll x=0, res = 0;
	vll v;
	REP(i,1,min(a,b)+1){
		ans++;
		if (a % i == 0 && b % i == 0) v.pb(i);
	}
	sort(reall(v));
	//rep(i, v.size())cout << v[i] << endl;
	cout << v[c-1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

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

int n, m, k, val[3010][3010];
ll memo[3010][3010][4];

ll dp(int i, int j, int taken) {
	if (i == n - 1 and j == m - 1) {
		if (taken == 3) return 0;
		return val[n - 1][m - 1];
	}
	if (memo[i][j][taken] != -1) return memo[i][j][taken];
	if (i == n - 1 and j != m - 1) {
		if (taken == 3)
			return memo[i][j][taken] = dp(i, j + 1, taken);
		ll v = 0;
		if (val[i][j] != 0)
			v = val[i][j];
		return memo[i][j][taken] = max(dp(i, j + 1, taken), dp(i, j + 1, taken + 1) + v);
	}
	if (i != n - 1 and j == m - 1) {
		ll v = 0;
		if (val[i][j] != 0)
			v = val[i][j];
		return memo[i][j][taken] = dp(i + 1, j, 0) + v;
	}
	if (taken == 3)
		return memo[i][j][taken] = max(dp(i + 1, j, 0), dp(i, j + 1, taken));
	else {
		if (val[i][j] != 0) {
			ll v = val[i][j];
			return memo[i][j][taken] = max({dp(i + 1, j, 0) + v, dp(i, j + 1, taken), dp(i, j + 1, taken + 1) + v});
		}
		else {
			return memo[i][j][taken] = max(dp(i + 1, j, 0), dp(i, j + 1, taken));
		}
	}
}

int main() {
	optimizar_io
	int r, c, v;
	cin >> n >> m >> k;
	while (k--) {
		cin >> r >> c >> v;
		val[r - 1][c - 1] = v; 
	}
	memset(memo, -1, sizeof(memo));
	cout << dp(0, 0, 0) << "\n";
	return 0;
}

Measured memory_bytes: 322420
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	while(cin >> s) {
		string yaki = "YAKI";
		if(SZ(s) < 4) {
			cout << "No" << endl;
		} else {
			string ans = "Yes";
			REP(i,4){
				if(yaki[i] != s[i]) {
					ans = "No";
				}
			}
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
/* Matrix Chain Multiplication */
#include<stdio.h>

int m[101][101];
int n;
void MatrixChainOrder(int p[]);

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

  int p[n+1];

  for(i=0;i<n;i++){
    scanf("%d %d",&r,&c);
    p[i]=r;
  }
  p[i]=c; /*i==n*/

  MatrixChainOrder(p);

  printf("%d\n",m[1][n]);
  
  return 0;

}

void MatrixChainOrder(int p[]){
  int i,j,k,l,q;
  /*n=length[p]-1 ... already inputted*/
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=2147483647; /*2147483647 is max of int*/
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j]<q){
	}else{
	  m[i][j]=q;
	}
      }
    }
  }
}

Measured memory_bytes: 0
n,w=map(int,input().split())
val=[0]*n
wt=[0]*n
dp=[[0 for x in range(w+1)] for x in range(n+1)] 
for i in range(n):
  a,b=map(int,input().split())
  wt[i]=a
  val[i]=b
for i in range(1,n+1):
    for j in range(1,w+1):
        if(wt[i-1] <= j):
            dp[i][j]=max(val[i-1] + dp[i-1][j-wt[i-1]] , dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][w])

Measured memory_bytes: 171528
#include "bits/stdc++.h"

#define int long long

using namespace std;

signed main(void) {

  int ans = 0;

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

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

  for (int i = 0; i < n - 1; ++i) {
    int tmp = abs(b[i] - c[i + 1]);
    if (i == 0) ans = tmp;
    else ans = min(ans, tmp);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using u8t = std::uint64_t;
using i8t = std::int64_t;
#define F(I,N) for(i8t I=0,_N=N;I<_N;I++)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
int main() {
  R(n)RV(a,n);
  // std::vector<i8t> b;
  // F(i,n){b.push_back(a[i]);}
  // std::reverse(b.begin(),b.end());
  // F(i,n){if(i)std::cout<<" ";std::cout<<b[i];}
  // std::cout<<std::endl;
  if(n%2==0){
    F(i,n){
      if(i)std::cout<<" ";
      if(i<n/2)
        std::cout<<a[n-1-2*i];
      else
        std::cout<<a[2*(i-n/2)];
    }
  }else{
    F(i,n){
      if(i)std::cout<<" ";
      if(i<=n/2)
        std::cout<<a[n-1-2*i];
      else
        std::cout<<a[1+2*(i-n/2-1)];
    }
  }
  std::cout<<std::endl;

  return 0;
}

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



           //       |----|       /\      |    |   -----   |
           //       |   /       /  \     |    |     |     |
           //       |--/       /----\    |----|     |     |
           //       |   \     /      \   |    |     |     |
           //       |    \   /        \  |    |   -----   -------

int n,m;
int arr[1005][1005];
int cache[1005][1005];
int mod=1000000007;
int dp(int x,int y)
{
	if(x==n&&y==m)
		return 1;
	if(cache[x][y]!=-1)
		return cache[x][y];
	int ans=0;
	if(arr[x+1][y]==1)
		ans=dp(x+1,y);
	ans%=mod;
	if(arr[x][y+1]==1)
		ans+=dp(x,y+1);
	ans%=mod;
	return cache[x][y]=ans;
}
int32_t main()
{
    IOS
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	string s;
    	cin>>s;
    	for(int j=1;j<=m;j++)
    		arr[i][j]=((s[j-1]=='.')?1:0);
    }
    memset(cache,-1,sizeof(cache));
    cout<<dp(1,1);
}

Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,tot=0;
    for(int i=1;i<=3;i++){
        scanf("%d",&x);
        tot=tot*10+x;
    }
    tot%4==0?printf("YES\n"):printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#1:初期化
N = int(input())
a = [None]*N
for i in range(N):
    a[i] = list(map(int,input().split()))
dp = [[0]*3 for _ in range (N+1)]
#print(dp, sep="\n")
#print(a, sep="\n")

#2:初期値(元からゼロなので記述無し)

#3:dp実行部(貰うDP)
for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if(j == k):
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i-1][j]) #dpは[1]からだが，aは[0]からに注意

#4:出力
dpmax = 0
for i in range(3):
    dpmax= max(dp[N][i], dpmax)
#print(*dp, sep="\n")
print(dpmax)


Measured memory_bytes: 47388
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
#define ll long long int
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
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;}
using namespace std;
int main(int argc, char const *argv[]) {
    ll n;
    while (cin >> n, n)
    {
        vector<pair<string,ll> > v(n+1);
        rep(i, n)
        {
            cin >> v[i].first;
            ll cnt = 0;
            rep(j, v[i].first.size())
            {
                //cout << v[i].first[j];
                if (v[i].first[j] == '.'){
                    cnt++;
                    v[i].first[j] = ' ';
                }
                else
                {
                    v[i].second = cnt;
                }
            }
        }
        
        rep(i,n){
            reps(j,i,n){
                if(v[i].second==v[j].second){
                    bool f = true;
                    reps(s, i + 1, j)
                    {
                        if (!(v[s].second >= v[i].second))
                        {
                            f = false;
                        }
                    }
                
                    if(f){
                        reps(s,i+1,j){
                            v[s].first[v[i].second - 1] = '|';
                        
                        }
                    }
                }

            }
        }
        rep(i, n)
        {
            if (v[i].second > 0&&v[i].first.find("+")==string::npos)
                v[i].first[v[i].second - 1] = '+';
        }
        rep(i,n){
            cout << v[i].first << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int  H[100005];
vector< pair<int, int> > h;
vector<int> g[100005];
bool vis[100005];

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n,m;cin>>n>>m;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    h.push_back({t, i});
    H[i]=t;
  }
  sort(h.rbegin(), h.rend());
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;a--,b--;
    g[a].push_back(b);g[b].push_back(a);
  }
  int ans=0;
  for(auto p : h) {
    // cout<<p.first<<endl;

    int hei = p.first;
    int v = p.second;
    if(vis[v])continue;
    vis[v]=1;
    bool ok=1;

    for (auto u : g[v]){
      vis[u]=1;
      if(hei <= H[u])ok=0;
    }

    if(ok){
      ans++;
    // cout<<v<<endl;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 9748
def solve(string):
    from itertools import combinations_with_replacement
    n, m, q, *abcd = map(int, string.split())
    ans = 0
    for v in combinations_with_replacement(range(1, m + 1), n):
        ans = max(
            ans,
            sum(d if v[b - 1] - v[a - 1] == c else 0 for a, b, c, d in zip(*[iter(abcd)] * 4)))
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define rrep(n) for(int i = n-1;i>=0;i--)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a)-1]
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
 
// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
 
//primes for hashing 937,991,1013,1409,1741
 
//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
/* Long Long Int */
#define int long long int


 
void solve(){
    int n;
    cin>>n;

    vector<int> v((int)1e5+5);
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i];

    }
    vector<int> dp((int)1e5+5);

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(v[1]-v[0]);
    for (int i = 2; i <= n; ++i)
    {
        dp[i+1] = min(dp[i] + abs(v[i]-v[i-1]), dp[i-1] + abs(v[i]-v[i-2]));
    }
    cout<<dp[n]<<endl;
    return;

}

signed main()
{
    FAST
    int t = 1;
    // cin>>t;
    while(t--) solve();
    return 0;

return 0;
}

Measured memory_bytes: 1792
#ABC128-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,k=IL()
V=IL()
ans=0

for i in range(min(k+1,n+1)):
    
    
    for j in range(i+1):
        t=0
        m=[]
        for l in range(j):
            if V[l]<0:
                m.append(V[l])
            else:
                t+=V[l]
        for l in range(i-j):
            if V[-l-1]<0:
                m.append(V[-l-1])
            else:
                t+=V[-l-1]
        m.sort(reverse=True)
        if len(m)>k-i:
            t+=sum(m[:len(m)-(k-i)])
       
        
        ans=max(ans,t)
print(ans)

Measured memory_bytes: 41584
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define MOD 1000000007
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
int a[100000];
int main() {
	int n, l;
	scanf("%d%d", &n, &l);
	fup(i,0,n-1,1)
		scanf("%d", a + i);
	int Max= 0, what = -1;
	fup(i,1,n-1,1)
		if (a[i] + a[i - 1] > Max)
			what = i, Max = a[i] + a[i - 1];
	if (Max < l)
	{
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	fup(i, 1, n - 1, 1)
	{
		if (i != what)printf("%d\n", i);
		if (i == what)break;
	}
	fdn(i, n-1, 1, 1)
	{
		if (i != what)printf("%d\n", i);
		if (i == what)break;
	}
	printf("%d", what);
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long           ll;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}

ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
void yes_or_no(ll x) {
  if (x) cout << "YES\n"; else cout << "NO\n";
}

int n, edges;
vector<vector<int>> graph;
vector<int> vis;
void addEdge(int u, int v) {
  graph[u].push_back(v);
  graph[v].push_back(u);

}
void init() {
  graph = vector<vector<int>>(n + 1);
  vis = vector<int>(n + 1, 0);
}
void input() {
  cin >> n >> edges;
  init();
  int u, v;
  for (int i = 0; i < edges; i++) {
    cin >> u >> v;
    addEdge(u, v);
  }
}
void dfs(int u) {
  vis[u] = 1;

  for (int i : graph[u]) if (vis[i] == 0)
      dfs(i);
}
void solve_test() {
  ll ans = 0;
  input();

  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) {
      dfs(i);
      ans++;
    }
  ans--;
  cout << ans;

}
int main()
{
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
// cin >> t; while (t--)
  solve_test();
  return 0;
}


Measured memory_bytes: 9536
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}

const int LG = 20;
const int MN = 100100;
int n;
ll x[MN], l;

int fr[LG][MN], ba[LG][MN];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", x+i);
    }
    scanf("%lld", &l);

    for (int i = 0; i < n; i++) {
        fr[0][i] = upper_bound(x, x+n, x[i]+l) - x - 1;
        ba[0][i] = lower_bound(x, x+n, x[i]-l) - x;
    }

    for (int fe = 1; fe < LG; fe++) {
        for (int i = 0; i < n; i++) {
            fr[fe][i] = fr[fe-1][fr[fe-1][i]];
            ba[fe][i] = ba[fe-1][ba[fe-1][i]];
        }
    }
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int x, y;
        scanf("%d %d", &x, &y); x--; y--;
        int ans = 0;
        if (x < y) {
            for (int fe = LG-1; fe >= 0; fe--) {
                if (fr[fe][x] < y) {
                    x = fr[fe][x];
                    ans += 1<<fe;
                }
            }
        } else {
            for (int fe = LG-1; fe >= 0; fe--) {
                if (ba[fe][x] > y) {
                    x = ba[fe][x];
                    ans += 1<<fe;
                }
            }
        }
        printf("%d\n", ans+1);
    }
    return 0;
}

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

using namespace std;

int main()
{
    int x=0;
    char y[4];
    cin>>y;
    for(int i=0; i<4; i++)
    {
        if(y[i]=='+')
        {
            x++;
        }
        else if(y[i]=='-')
        {
            x--;
        }
    }
    cout<<x<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,k,r=1;
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    if(r*2<r+k)r*=2;
    else r+=k;
  }
  printf("%d",r);
  return 0;
}

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

int main() {
    long long n, c;
    cin >> n >> c;
    long long x[n], v[n], dp[n + 1], result = 0;
    dp[0] = 0;
    for (long long i = 0; cin >> x[i] >> v[i]; i++) {
    }
    for (long long i = 0, sum = 0; i < n; i++) {
        sum += v[i];
        dp[i + 1] = max(dp[i], sum - x[i]);
    }
    result = max(result, dp[n]);
    for (long long i = n - 1, sum = 0; i > 0; i--) {
        sum += v[i];
        result = max(result, sum - 2 * (c - x[i]) + dp[i]);
    }
    dp[n] = 0;
    for (long long i = n - 1, sum = 0; i >= 0; i--) {
        sum += v[i];
        dp[i] = max(dp[i + 1], sum - c + x[i]);
    }
    result = max(result, dp[0]);
    for (long long i = 0, sum = 0; i < n; i++) {
        sum += v[i];
        result = max(result, sum - 2 * x[i] + dp[i + 1]);
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 2560
n=gets.to_i
a=gets.chomp.split(" ").map(&:to_i)

def Whatcnt(_num)
	r=_num%2
	cnt=0
	while(r==0)
		cnt+=1
		_num/=2
		r=_num%2
	end
	return cnt
end
sum=0
a.each do|i|
	sum+=Whatcnt(i)
end
puts sum

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n, k, x, y;
	cin >> n >> k >> x >> y;

	cout << min(n, k) * x + max(0, (n-k)) * y << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<a+b+c+(max({a,b,c})*(pow(2,k)-1))<<endl;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let dx = vec![1,0,-1,0];
    let dy = vec![0,1,0,-1];
    let h:usize = read();
    let w:usize = read();

    let mut map:Vec<Vec<char>> = vec![vec![' ';w];h];
    let mut cost:Vec<Vec<u64>> = vec![vec![std::u64::MAX;w];h];
    let mut count_black = 0;

     for i in 0..h{
        map[i] = read::<String>().chars().collect();
        count_black += map[i].iter().filter(|c| **c == '#').count();
    }
    let mut q: VecDeque<(usize,usize)> = VecDeque::new();
    cost[0][0] = 1;
    q.push_back((0,0));

    while !q.is_empty(){
        let xy = q.pop_back().unwrap();
        let x = xy.0;
        let y = xy.1;

        for dir in 0..4{
            let nx = x as isize + dx[dir];
            let ny = y as isize + dy[dir];
            //場外判定
            if nx < 0 || nx >= h as isize || ny < 0 || ny >= w as isize {
                continue;
            }
            let nx = nx as usize;
            let ny = ny as usize;
            //壁判定
            if map[nx][ny] == '#'{
                continue;
            }

            if cost[nx][ny] > cost[x][y] + 1{
                cost[nx][ny] = cost[x][y] + 1;
                q.push_back((nx,ny));    
            }
        }
    }

    //println!("{:?}",cost);
    //println!("{:?}",map);

    if cost[h-1][w-1] == std::u64::MAX {
        println!("-1");
    }else{
        println!("{}",h*w - cost[h-1][w-1] as usize - count_black);
    }



}


Measured memory_bytes: 2216
# -*- coding: utf-8 -*-


def main():
    n, m, x, y = map(int, input().split())
    xs = list(map(int, input().split())) + [x]
    ys = list(map(int, input().split())) + [y]

    if max(xs) < min(ys):
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
# モジュールのインポート
import sys

# 標準入力を取得
A, B, C, X, Y = list(map(int, input().split()))

# 求解処理
ans = sys.maxsize
for c in range(0, 2 * max(X, Y) + 1, 2):
    a = max(0, X - c // 2)
    b = max(0, Y - c // 2)
    ans = min(ans, A * a + B * b + C * c)

# 結果出力
print(ans)

Measured memory_bytes: 9156
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let l: usize = read!();
    let r: usize = read!();
    let d: usize = read!();

    let r = r / d;
    let l = (l - 1) / d;
    println!("{}", r - l);
}


Measured memory_bytes: 2076
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int DP[50005];

int main() {
    int N, M;
    cin>>N>>M;
    vector<int> C(M);
    for(int i=0;i<M;++i){
        cin>>C[i];
    }
    for(int i=1;i<=N;++i){
        DP[i] = inf;
    }
    for(int i=1;i<=N;++i){
        for(int j=0;j<M;++j){
            if(i<C[j]) continue;
            DP[i] = min(DP[i], DP[i-C[j]]+1);
        }
    }
    cout<<DP[N]<<endl;
}



Measured memory_bytes: 3272
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(str, str(input().rstrip('\n')).split()))
    if a > b:
        print(">")
    elif a < b:
        print("<")
    else:
        print("=")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38316
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

"""
s = S()
n = len(s)
if s == list("keyence"):
    print("YES")
    quit()
for i in range(n):
    for j in range(i+1,n):
        print(s[:i]+s[j:])
        if s[:i]+s[j:] == list("keyence"):
            print("YES")
            quit()
print("NO")
"""
#B
c = LIR(3)
v = [[] for i in range(4)]
for i in range(3):
    c[i][0] -= 1
    c[i][1] -= 1
    v[c[i][0]].append(c[i][1])
    v[c[i][1]].append(c[i][0])

for i in range(4):
    li = [True for i in range(4)]
    li[i] = False
    q = [i]
    c = 0
    while q:
        x = q.pop(-1)
        k = 0
        for j in v[x]:
            if li[j]:
                li[j] = False
                q.append(j)
                if k == 0:
                    c += 1
                    k += 1
    if c == 3:
        print("YES")
        quit()
print("NO")
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38896
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
const long long mod=1e9+7;
long long n,k,s1[2005],s2[2005],ans,a[2005];
int main()
{
	fast;
	cin>>n>>k;
	for (long long i=1;i<=n;i++)
	   cin>>a[i];
	for (long long i=1;i<=n;i++)
	   for (long long j=1;j<=n;j++)
	      if (a[j]<a[i])
	         s1[i]++;
	for (long long i=2;i<=n;i++)
	   for (long long j=1;j<=i;j++)
	      if (a[j]<a[i])
	         s2[i]++;
	for (long long i=1;i<=n;i++)
	{
		ans=ans+((k*(k+1)/2%mod)*(s1[i]%mod)-(s2[i]*k%mod))%mod;
		if (ans<0)
		   ans+=mod;
		ans=ans%mod;
	}

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

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	int n;
	cin >> n;
	vector<tuple<string, int, int>> a;

	REP(i,1, n+1) {
		string s;
		int p;
		cin >> s >> p;
		p = -p;
		a.push_back(tie(s, p, i));
	}
	sort(a.begin(), a.end());
	rep(i, n) {
		cout << get<2>(a[i]) << endl;
	}
	return 0;
}

Measured memory_bytes: 256