akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 998244353;



bool** dp; 
ll ans= 0,n;
ll power(ll a, ll b)	//a is base, b is exponent
{
	if(b==0)
		return 1;
	if(b==1)
		return a % mod;
	if(b%2 == 1)
		return (power(a,b-1)*a) % mod;
	ll q = power(a,b/2);
	return (q*q) % mod;
}



ll isSubsetSum(ll set[], ll n, ll sum) 
{ 
    // The value of subset[i][j] will be true if 
    // there is a subset of set[0..j-1] with sum 
    // equal to i 
    ll subset[n + 1][sum + 1];
    mem(subset,0LL); 
  
 
    for (ll i = 0; i <= n; i++) 
        subset[i][0] = 1; 
    for (ll i = 1; i <= sum; i++) 
        subset[0][i] = 0; 
  
   
    for (ll i = 1; i <= n; i++) { 
        for (ll j = 0; j <= sum; j++) { 
         
                subset[i][j] = 2*subset[i - 1][j] % mod; 
            if (j >= set[i - 1]) 
                subset[i][j] = (subset[i][j] + subset[i - 1][j - set[i - 1]]) % mod; 
        } 
    }
    ans = 0;
    
    return subset[n][sum]; 
 } 

void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll m,k;
  cin>>n >> k;
  ll a[n];
  for (ll i = 0; i < n; ++i){
  	cin >> a[i];
  }
  c(isSubsetSum(a,n,k));
  
 
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //ll T;cin >> T;while (T--)
  solve();
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 1e5 + 3;
int n;
vector<int> V[MC];

int main(){
	cin >> n;
	repp(i,1,n){
		int a,b; cin >> a >> b;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	if(n == 2) return cout << "1 2" << endl , 0;
	int w;
	repp(i,1,n+1){
		int c = 0;
		for(auto z : V[i]) if(V[z].size() > 1) ++c;
		if(c > 2) return cout << -1 << endl , 0;
		if(V[i].size() > 1 && c <= 1) w = i;
	}
	vector<int> u;
	int pr = 0;
	while(w){
		u.push_back(V[w].size()-2);
		int nx = 0;
		for(auto z : V[w]) if(z != pr && V[z].size() > 1) nx = z;
		pr = w; w = nx;
	}
	repp(i,0,u.size()) if(u[i] != u[u.size()-1-i]){
		if(u[i] > u[u.size()-1-i]) reverse(u.begin(),u.end());
		break;
	}
	int s = 2;
	cout << 1 << ' ';
	for(auto z : u){
		repp(i,s+1,s+z+1) cout << i << ' ';
		cout << s << ' ';
		s += z+1;
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 6784
a, b, c, d, e, f = map(int, input().split())
water = []
for i in range(31):
    for j in range(31):
        if a*i+b*j <= f//100:
            water.append(a*i+b*j)
water.pop(water.index(0))
water = list(set(water))
result = [[0,0,0]]
for w in water:
    for i in range(301):
        for j in range(301):
            sugar = c*i+d*j
            if sugar <= w*e and sugar+w*100 <= f: 
                result.append([100*sugar/(sugar+w*100), (sugar+w*100), sugar])
result.sort(reverse=True)
print(result[0][1], result[0][2])

Measured memory_bytes: 75512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> a(n+1,2);
  a[1] = 1;
  for (ll i = 2; i <= n/2; i++) {
    for (ll j = 2; j*i <= n; j++) {
      a[i*j]++;
    }
  }
  rep(i,n) {
    ans += a[i+1] * (i+1);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 81288
import java.util.Scanner;

public class Main {

    static int n;
    static Node[] node;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        
        node = new Node[n];
        int l,r;
        l = r = 0;
        for(int i = 0; i < n; i++){
            node[i] = new Node();
        }
        int v;
        for(int i = 0; i< n;i++){
            v = sc.nextInt();
            l = sc.nextInt();
            r = sc.nextInt();
            node[v].l = l;
            node[v].r = r;
            if( l != -1) node[l].p = v;
            if( r != -1) node[r].p = v;
        }

        int root=0;
        for(int i = 0; i< n;i++){
            if (node[i].p == -1) root = i;
        }
        System.out.println("Preorder");
        preOrder(root);
        System.out.println("\nInorder");
        Inorder(root);
        System.out.println("\nPostorder");
        Postorder(root);
        System.out.println();

    }
    
    static void preOrder(int u){
        if(u == -1)return;
        System.out.print(" " + u);
        preOrder(node[u].l);
        preOrder(node[u].r);
        return;
    }
    
    static void Inorder(int u){
        if(u == -1) return;
        Inorder(node[u].l);
        System.out.print(" "+ u);
        Inorder(node[u].r);
    }
    
    static void Postorder(int u){
        if(u == -1) return;
        Postorder(node[u].l);
        Postorder(node[u].r);
        System.out.print(" "+ u);
    }

}

class Node{
    int p,r,l;
    Node(){
        p = r = l = -1;
    }
}


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

using namespace std;

typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define mp(p, q) make_pair(p, q)
//３つ以上の値をセットに(3より多いときはカッコ内を増やす)\
sort -> p -> q -> r
#define mt(p, q, r) make_tuple(p, q, r)
#define all(a) a.begin(), a.end()

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

//配列を反転
template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Down(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end(), greater<ll>()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b, greater<ll>()));
  }
}

  void Main()
  {
    ll n; cin >> n;
    vll p(n); V(p);
    ll ans = p[0], flag = 0;
    for(ll i = 0;i < n;i++)
    {
      ans = min(ans, p[i]);
      if(ans == p[i]) flag++;
    }
    fin(flag)
  }

  int main()
  {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20); //高精度少数表示
    Main();
    return 0;
  }

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        for (int i = 0; i < s.length(); i++) {
            if (s.equals(t)) {
                System.out.println("Yes");
                return;
            }
            s = s.charAt(s.length() - 1) + s.substring(0, s.length() - 1);
        }

        System.out.println("No");
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long N, long long X, std::vector<long long> L) {
    ll p = 0;
    ll cnt = 0;
    for (auto i : L) {
        p += i;
        if (p > X) {
            break;
        } else {
            cnt++;
        }
    }
    cout << cnt + 1 << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long X;
    scanf("%lld", &X);
    std::vector<long long> L(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &L[i]);
    }
    solve(N, X, std::move(L));
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const ll N = 2e5 + 10;
int dp[N], ans;
bool vis[N];
vector < int > edges[N];
int dfs(int x){
    if(vis[x])return dp[x];
    vis[x] = true;
    dp[x] = 1;
    for(int i : edges[x]){
        dp[x] = max(dp[x], dfs(i) + 1);
    }
    return dp[x];
}
int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            ans = max(ans, dfs(i));
        } 
    }
    cout << --ans << endl;
}   

Measured memory_bytes: 9856
#include <stdio.h>
int main(){
  int H,W,i,j;
  while(1){
    scanf("%d%d",&H,&W);
    if(H==0 && W==0){
      break;
    }
for(j=0;j<H;j++)
{
for(i=0;i<W;i++)
{
    if(i<W-1){
      printf("#");
  }
    else{
      printf("#\n");
    }
 }
 }printf("\n");
  }
  return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    while(cin >> n, n){
        cin >> m;
        int ans = 0, cnt = 0;
        string s;
        cin >> s;
        for (int i = 0; i < m; ++i) {
            char target = (cnt%2 ? 'O' : 'I');
            if(s[i] == target) cnt++;
            else {
                ans += max(0, (cnt-1)/2-n+1);
                cnt = 0;
                target = (cnt%2 ? 'O' : 'I');
                if(s[i] == target) cnt++;
            }
        }
        cout << ans << "\n";
    }

    return 0;
}



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

void print(char c, int num) {
  for (int i = 0; i < num; i++) cout << c;
}

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  print('U', dy);
  print('R', dx);
  print('D', dy);
  print('L', dx + 1);
  print('U', dy + 1);
  print('R', dx + 1);
  print('D', 1);
  print('R', 1);
  print('D', dy + 1);
  print('L', dx + 1);
  print('U', 1);
  cout << endl;
}

Measured memory_bytes: 256
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    string s;
    cin>>s;
    ll i,c=0,ans=0;
    for(i=0;i<3;i++)
    {
        if(s[i]=='R')
            c++;
        else
        {
            ans=max(ans,c);
            c=0;
        }
    }
    cout<<max(ans,c)<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 w, h;
    std::cin >> w >> h;
    std::vector<i64> p(w), q(h);
    for (int i = 0; i < w; i++) std::cin >> p[i];
    for (int i = 0; i < h; i++) std::cin >> q[i];

    std::sort(p.begin(), p.end());
    std::sort(q.begin(), q.end());

    i64 ret = 0;
    i64 x = 0, y = 0;
    for (int i = 0; i < h + w; i++) {
        if (y == h || (x < w && p[x] < q[y])) {
            ret += p[x] * (h - y + 1);
            x++;
        } else {
            ret += q[y] * (w - x + 1);
            y++;
        }
    }
    std::cout << ret << std::endl;

    return 0;
}


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

int main() {
   long long  n;
   cin >> n;
   vector<long long> a(100000);
   vector<long long > b(100000);
   
   for(long long  i=0 ; i < n ; i++ ){
      cin >> a.at(i);
   }
   long long c=0;
   for(long long j=0; j<n ; j++){
       if (j==0) b.at(j) ==0;
	   
	   if(j>0&& j<n) { 
	       b.at(j) = (a.at(j-1)-b.at(j-1)/2) *2;
	   }
	   
	   
	   
   }
   
   c= a.at(n-1) - b.at(n-1)/2 ;
  
   for(long long  k=0;k<n ; k++ ) {
      if(k%2==0)  cout <<b.at(k) + c << endl;
      
      else {  cout << b.at(k) - c   << endl; 
      }
   }
   
   

}

Measured memory_bytes: 2944
import sys
sys.setrecursionlimit(10**9)
def dfs(parent,current,distance):
  global m
  m[current]=distance
  for child in graph[current]:
    if child[0]==parent:
      continue
    dfs(current,child[0],distance+child[1])
n=int(input())
graph=[]
for i in range(n+1):
  graph.append([])
m=[0]*(n+1)
for i in range(n-1):
  a,b,c=map(int,input().split())
  graph[a].append([b,c])
  graph[b].append([a,c])
dfs(1,1,0)
for i in range(1,n+1):
  if m[i]%2==0:
    print(1)
  else:
    print(0)

Measured memory_bytes: 181860
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem1126 : The Secret Number **/
const int MAX_W = 70;
int W, H;
char field[MAX_W][MAX_W];
string dp[MAX_W][MAX_W];

string big(string s1, string s2) {
	if (s1.length() > s2.length()) {
		return s1;
	} else if (s2.length() > s1.length()) {
		return s2;
	} else {
		return (s1>s2?s1:s2);
	}
}

string big2(string s1, string s2) {
	while (s1[0]=='0') s1.erase(s1.begin());
	while (s2[0]=='0') s2.erase(s2.begin());
	return big(s1, s2);
}

string rec(int x, int y)
{
	if (!('0' <= field[y][x] && field[y][x] <= '9'))
		return dp[y][x] = "";
	
	string s1 = dp[y][x+1];
	string s2 = dp[y+1][x];
	
	return dp[y][x] = field[y][x] + big(s1, s2);
}

int main()
{
	while (cin>>W>>H, W||H) {
		fill(dp[0], dp[0]+MAX_W*MAX_W, "");
		
		rep(i, H) {
			rep(j, W) {
				cin>>field[i][j];
			}
		}
		
		string ans = "";
		rep(y, H) {
			rep(x, W) {
				ans = big2(ans, rec(W-x-1, H-y-1));
				
			}
		}
		
		cout << (ans!=""?ans:"0") << endl;
	}
}

Measured memory_bytes: 1396
N=int(input())
li=list(map(int,input().split()))
ave1=sum(li)//N
ave2=sum(li)//N+1
ave3=sum(li)//N-1
ans1=0
ans2=0
ans3=0
for n in range(len(li)):
  ans1+=(li[n]-ave1)**2
  ans2+=(li[n]-ave2)**2
  ans3+=(li[n]-ave3)**2
print(min(ans1,ans2,ans3))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010];

int main() {

    int n, k;
    cin >> n >> k;

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

    for (int i = 0; i < 100010; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i-j >= 0) chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <vector>
using namespace std;
vector<int> e[100010];
int dp[100010], p;
void dfs(int v, int p = -1) {
	int c = 0, k = 0;
	for (int i = 0; i < e[v].size(); i++) {
		int w = e[v][i];
		if (w == p) continue;
		dfs(w, v);
		if (dp[w]) {
			k += dp[w];
		} else {
			c++;
		}
	}
	int cn = e[v].size();
	dp[v] = k;
	if (c > 0) {
		dp[v] += c - 1;
	} else {
		p = v;
	}
}
int dfs2(int v, int p = -1) {
	int c = 0, f = 0;
	for (int i = 0; i < e[v].size(); i++) {
		int w = e[v][i];
		if (w == p) continue;
		if (e[v].size() <= 2) {
			return dfs2(w, v);
		} else {
			f |= !dp[w];
			c++;
		}
	}
	return c == 0 || f;
}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for (int i = 0; i < n; i++) {
		if (e[i].size() == 1) {
			dfs(i);
			printf("%d\n", dp[i] + dfs2(i));
			break;
		}
	}
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	int result = 0;
	for( int i = 1; i <= 50000; ++i ) {
		if( i * 108 / 100 == N ) {
			result = i;
			break;
		}
	}

	if( result == 0 ) {
		cout << ":(\n";
	}
	else {
		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if (s=="RRR"){
        cout<<3;
    }
    else if (s=="RRS" | s=="SRR"){
        cout<<2;
    } 
    else if (s=="SSS"){
        cout<<0;
    }
    else{
        cout<<1;
    }

}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int n = 0,count = 0;
	int f = 0;
	std::cin >> n;
	for (int i = 1; i <= n; i += 2) {
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {
				f++;
			}
		}
		if (f == 8) {
			count++;
		}
		f = 0;
	}
	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d[105][3];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> d[i][1] >> d[i][2];
	}
	for (int i = 1; i <= n - 2; i ++) {
		bool flg = true;
		for (int j = i; j <= i + 2; j ++) {
			if (d[j][1] != d[j][2]) flg = false;
		}
		if (flg) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s;

signed main() {
	cin >> s;
	cout << s.substr(0,s.size()-8) << endl;
}

Measured memory_bytes: 256
<?php
// Here your code !
$stdins = array();
$i = 0;
    while(true)
    {
        $stdin = trim(fgets(STDIN));
        if ($stdin === '')
        {
            return;
        }
        $nums = explode(' ', $stdin);
        rsort($nums);
        if (array_sum($nums) == 0) {
            continue;
        }
        $result = 0;
        foreach ($nums as $index => $num) {
            if ($num > 9) {
                $result += 10;
            } else if ($num != 1) {
                $result += $num;
            } else {
                if (count($nums) != $index + 1 || $result > 10) {
                    $result += 1;
                } else {
                    $result += 11;
                }
            }
        }
        if ($result > 21) {
            echo "0" . "\n";
        } else {
            echo $result . "\n";
        }
    }
?>

Measured memory_bytes: 15164
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    private static int Q;
    private static int N;
    private static int M;
    private static int[] a;
    private static int[] b;
    private static int[] c;
    private static int[] d;

    public static void main(String[] args) {
        int N = nextInt();
        int K = nextInt();
        boolean[] sunu = new boolean[N];
        for(int i=0; i<K; i++){
            int d = nextInt();
            for(int j=0; j<d; j++){
                sunu[nextInt()-1] = true;
            }
        }

        int count=0;
        for(int i=0; i<N; i++){
            if(!sunu[i]){
                count++;
            }
        }
        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


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

int main(){
    int N, K, A[100];
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i];
    bitset<100001> dp;
    dp[0] = 1;
    for(int i=1; i<=K; i++){
        dp[i] = 1;
        for(int j=0; j<N; j++){
            if(i-A[j]>=0 && dp[i-A[j]]) dp[i] = 0;
        }
    }
    cout << (dp[K] ? "Second" : "First") << endl;
    return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll gcd(ll a, ll b) { return (a == 0) ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

void solve() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

  vector<int> A(3) ;
  rep(i,3) cin >> A.at(i) ;
  sort(A.begin(),A.end());
  cout << A.at(1)*A.at(0)/2 << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

ll n;
vl a;

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	a.resize(n);
	rep(i,0,n) {
		cin >> a[i];
	}

	ll A = 0;
	rep(i,0,n) {
		A += a[i];
	}
	if((A*2) % (n*n + n)) {
		cout << "NO" << '\n';
		return 0;
	} 

	ll B = (A*2) / (n*n + n);
	vl b;
	b.resize(n);
	rep(i,0,n) {
		ll x = B - a[(i+1)%n] + a[i];
		ll y = x % n;
		if((x < 0) || (x % n)) {
			cout << "NO" << '\n';
			return 0;
		}
		b[i] = x / n;
	}
	ll bsum = 0;
	rep(i,0,n) bsum += b[i];
	if(bsum == B) 
		cout << "YES" << '\n';
	else 
		cout << "NO" << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
#include <boost/multiprecision/cpp_int.hpp>
namespace mpl = boost::multiprecision;
using Bint = mpl::int128_t;
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  cin >> n;
  vector<Bint> a(n, 0);
  Bint ans = 1LL;
  REP(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      ans = 0;
    }
  }
  
  if (ans == 0) {
    cout << 0 << endl;
    return 0;
  }
  REP(i, n) {
    ans *= a[i];
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}
//////////////////////////////////////////////



Measured memory_bytes: 6368
l =[]
r=[]
n = int(input())
for i in range(n):
    l.append(input())
d={}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
print()
m = max(d.values())
for key,value in d.items():
    if value==m:
        r.append(key)
sorted_r = sorted(r)
print(*sorted_r,sep='\n')

Measured memory_bytes: 37136
<?php

list($N, $T) = explode(" ", trim(fgets(STDIN)));

$cost = 99999;
for($i = 0; $i < $N; $i++){
    list($c, $t) = explode(" ", trim(fgets(STDIN)));
    if($t > $T)continue;
    $cost = min($cost, $c);
}
echo $cost == 99999 ? "TLE" : $cost;


Measured memory_bytes: 4728
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.io.IOException;

// ALDS1_6_D
public class Main {
	int binarySearch(int[] array, int n, int min, int max) {
		if (min > max) return -1;
		int mid = (max + min) / 2;
		if (array[mid] == n) return mid;
		if (array[mid] > n) return binarySearch(array, n, min, mid-1);
		else return binarySearch(array, n, mid+1, max);
	}
	
	int SENTINEL = 1234567890;
	void merge(int[]A, int left, int mid, int right) {
		int n1 = mid - left + 1;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = A[mid + 1 + i];
		}
		L[n1] = SENTINEL;
		R[n2] = SENTINEL;
		int i = 0;
		int j = 0;
		for (int k = left; k <= right; k++) {
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i = i + 1;
			} else {
				A[k] = R[j];
				j = j + 1;
			}
	    }
	}

	void mergeSort(int[] A, int left, int right) {
	    	if (left < right) {
	    		int mid = (left + right)/2;
	    		mergeSort(A, left, mid);
	    		mergeSort(A, mid + 1, right);
	    		merge(A, left, mid, right);
	  	}
	}
	int cost = 0;
	void run() throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = 10000;
		int[] A = new int[n];
		boolean[] check = new boolean[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
			check[i] = false;
			if (min > A[i]) min = A[i];
		}
		int[] B = A.clone();
		mergeSort(B, 0, n-1);
		for (int i = 0; i < n; i++) {
			if (check[i]) continue;
			check[i] = true;
			if (A[i] == B[i]) continue;
			int loopmin = A[i];
			int count = 0;
			int j = i;
			while(true) {
				cost += A[j];
				j = binarySearch(B, A[j], 0, n-1);
				if (check[j]) break;
				if (loopmin > A[j]) loopmin = A[j];
				check[j] = true;
				count++;
			}
			cost -= loopmin;
			if ((count)*(loopmin-min) > 2*(min + loopmin))
				cost += 2*(min + loopmin) + count*min;
			else
				cost += count*loopmin;
		}
		System.out.println(cost);
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}



Measured memory_bytes: 30312
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

#define B       (cout << "Sehen Sie mich!" << endl)
#define VB(val) (cout << val << endl)

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

        ret = (1900 * m + 100 * (n - m)) * pow (2, m);
        VB(ret);
}

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

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

    if(r < 1200) cout << "ABC" << endl;
    else if(r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,x;
  cin>>n>>x;
  vector<int> l(n);
  vector<long long int> d(n+1);
  d.at(0)=0;
  for(int i=0; i<n; i++){
    cin>>l.at(i);
    if(i>0){
      d.at(i)=d.at(i-1)+l.at(i-1);
    }
  }
  d.at(n)=d.at(n-1)+l.at(n-1);

  int ans=0;
  for(int i=0; i<n+1; i++){
    if(d.at(i)<=x){
      ans=i+1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
n = [a, b, c, d, e]

zr = list(filter(lambda x: x % 10 == 0, n))
nz = list(filter(lambda x: x % 10 != 0, n))

nz.sort(key=lambda x: x % 10)

for i in range(1, len(nz)):
    nz[i] = 10 * (nz[i]//10+1)

print(sum(nz)+sum(zr))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			String[] s = str.split(" ",0);
			int N = Integer.parseInt(s[0]);
			int M = Integer.parseInt(s[1]);
			int[] table = new int[N];
			ArrayList<Integer> al = new ArrayList<>();
			for(int i=0;i<M;i++) {
				str = br.readLine();
				s = str.split(" ",0);
				int a = Integer.parseInt(s[0]);
				int b = Integer.parseInt(s[1]);
				if(a == 1) {
					al.add(b);
				}else if(b == 1) {
					al.add(a);
				}
				if(a == N) {
					table[b] = 1;
				}else if(b == N) {
					table[a] = 1;
				}
			}

			for(int i = 0;i<al.size();i++) {
				if(table[al.get(i)]==1) {
					System.out.println("POSSIBLE");
					break;
				}
				if(i == al.size()-1) {
					System.out.println("IMPOSSIBLE");
				}
			}

		}catch (Exception e) {
			System.exit(0);
		}
	}
}


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

int main(){
        int a,b,c,x;
        cin >> a >> b >> c >> x;
        int count=0,now;
        for(int i=0;i<=a;i++){
                now=x;
                now=now-500*i;
                for(int j=0;j<=b;j++){
                        now=x-500*i;
                        now=now-100*j;
                        for(int k=0;k<=c;k++){
                                now=x-500*i-100*j;
                                now=now-50*k;
                                if(now == 0){
                                        count++;
                                }
                        }
                }
        }
        cout << count << endl;
        return 0;
}

Measured memory_bytes: 256
import sys

def shuffle( cards ):
	h = int( sys.stdin.readline() )
	cards = cards[ h : ] + cards[ 0 : h ]
	return cards

while True:
	cards = sys.stdin.readline().rstrip()
	if '-' == cards:
		break
	m = int( sys.stdin.readline() )
	for i in range( m ):
		cards = shuffle( cards )
	print( cards )

Measured memory_bytes: 6724
#include <stdio.h>

int main()
{
    int n, a[100], i, j, tmp=0;
    scanf("%d\n", &n);
    for (i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (i=0; i<=n-2; i++)
    {
        for (j=i+1; j<=n-1; j++)
        {
            if (a[i] > a[j]) {
                tmp = a[j];
                a[j] = a[i];
                a[i] = tmp;
            }
        }
    }
    printf("%d\n", a[n-1] - a[0]);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
	int n, x, l;
	cin >> n;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> x >> l;
		v[i].first = x + l;
		v[i].second = l;
	}
	sort(v.begin(), v.end());
	int left = -2e9, ans = 0;
	for (int i = 0; i < n; ++i) {
		if (v[i].first - v[i].second * 2 >= left) {
			left = v[i].first;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
n, t = map(int, input().split())
box = []
for _ in range(n):
    s, t = map(int, input().split())
    box.append((s,1))
    box.append((t,0))

box = sorted(box)
cnt = 0
ans = 0
for x in box:
    a, b = x
    if b == 0:
        cnt -= 1
    else:
        cnt += 1
    ans = max(ans,cnt)
print(ans)


Measured memory_bytes: 28412
#include <stdio.h>
 
int main() {
    int p,q,r;
    int a,b,c,ans;
 
    scanf("%d",&p);
    scanf("%d",&q);
    scanf("%d",&r);
    
    a = p+q;
    b = q+r;
    c = r+p;
    
  if(a <= b)
    ans = a;
  else
    ans = b;
  if(ans >= c)
    ans = c;
  printf("%d",ans);
}

Measured memory_bytes: 128
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = input()

rs=0
gs=0
bs=0

for i in range(n):
  if s[i]=='R':
    rs+=1
  elif s[i]=='G':
    gs+=1
  else:
    bs+=1

total = rs*gs*bs

for i in range(n):
  for j in range(i+1,n):
    k=j+j-i
    if k<n:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        total-=1

print(total)


Measured memory_bytes: 9220
while True:
    table=input().split()
    a = int(table[0])
    op = table[1]
    b = int(table[2])


    if op == "+":
        print("%d"%(a+b))
    elif op == "-":
        print("%d"%(a-b))
    elif op == "*":
        print("%d"%(a*b))
    elif op == "/":
        print("%d"%(a/b))
    else:
        break;



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
const int MAX = 400000;
typedef long long ll;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve(long long n, long long k){
    COMinit();
    ll ret;
    if (k>=n){
        ret = COM(2*n-1,n);
    }else{
        ret = 0;
        for (ll m=0;m<=k;m++){
            ret += COM(n,m) * COM(n-1,m)%MOD;
        }
        ret %=MOD;
        
    }
    printf("%lld\n",ret);


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long n;
    scanf("%lld",&n);
    long long k;
    scanf("%lld",&k);
    solve(n, k);
    return 0;
}


Measured memory_bytes: 9600
sn = input()
k = int(input())
d = len(sn)

dp1 = [[0 for j in range(k + 1)] for i in range(d + 1)] # 未満
dp2 = [[0 for j in range(k + 1)] for i in range(d + 1)] # 未確定
dp2[0][0] = 1
for i in range(d):
    for j in range(k):
        if sn[i] == '0':
            dp2[i + 1][j] += dp2[i][j]
        else:
            dp2[i + 1][j + 1] += dp2[i][j] # i桁目が1以上で同じ場合
            dp1[i + 1][j + 1] += (int(sn[i]) - 1) * dp2[i][j] # i桁目が1以上N[i]未満の場合
            dp1[i + 1][j] += dp2[i][j] # i桁目が0の場合

        dp1[i + 1][j] += dp1[i][j]
        dp1[i + 1][j + 1] += dp1[i][j] * 9
    dp1[i + 1][k] += dp1[i][k]
    dp2[i + 1][k] += dp2[i][k]
print(dp1[-1][-1] + dp2[-1][-1])


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

n,w = inpl()
wv = [inpl() for i in range(n)]
dp = [[0 for i in range(w+1)] for j in range(n+1)]
wv.sort()
wv.sort(key=lambda x:x[1])
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = wv[i][0], wv[i][1]
for i in range(n-1):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
res = dp[n-1][w-1]+wv[n-1][1]

dp = [[0 for i in range(w+1)] for j in range(n+1)]
ww[-1],ww[-2] = ww[-2],ww[-1]
vv[-1],vv[-2] = vv[-2],vv[-1]
for i in range(n-1):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
print(max(res,dp[n-1][w-1]+vv[n-1]))


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

P p[500000];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d%d", &p[i].first, &p[i].second);
	sort(p, p + n);
	int Min = INT_MAX;
	rep(i, n) {
		for (int j = i - 1; j >= 0; j--) {
			int a = p[i].first - p[j].first, b = p[i].second - p[j].second;
			if (a*a >= Min)break;
			Min = min(Min, a*a + b*b);
		}
	}
	printf("%d\n", Min);
}

Measured memory_bytes: 7060
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
  itn n; cin >> n;
  vector<mint> a(n);
  rep(i,n) cin >> a[i];
  vector<mint> s(n);
  s[0]=a[0];
  rep(i,n-1) s[i+1]=s[i]+a[i+1];
  mint ans=0;
  rep(i,n){
    ans+=a[i]*(s[n-1]-s[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6280
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//std::ios::sync_with_stdio(false);

signed main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int n,i,ans=1,cnt[30]={0};
	cin>>n;
	string s;
	cin>>s;
	rep(i,s.length()){
		cnt[s[i]-'a']++;
	}	
	rep(i,26){
		ans*=(cnt[i]+1);
		ans%=mod;
	}
	ans--;
	ans%=mod;
	ans+=mod;
	ans%=mod;
	cout<<ans<<endl;
	return 0;
} 
	

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  rep(i,n){
    int d; cin >> d;
    mp[d]++;
    if(mp[d]>=3){ cout << 0 << endl; return 0; }
  }

  vector<int> pos;
  pos.push_back(0);
  pos.push_back(24);
  bool f = true;
  for(auto it:mp){
    if(it.S==2){
      pos.emplace_back(it.F);
      pos.emplace_back(24 - it.F);
    } else {
      if(f){
        pos.emplace_back(it.F);
        f = !f;
      } else {
        pos.emplace_back(24 - it.F);
        f = !f;
      }
    }
  }
  sort(pos.begin(),pos.end());
  int ans = inf;
  int m = pos.size();
  rep(i,m-1){
    ans = min(ans, pos[i+1]-pos[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs            v.size()
#define ss            s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii            pair<int, int>
#define int           long long
#define ull           unsigned long long
#define pb            push_back
#define mpp           make_pair
#define Okay          0
#define pi            3.14159

const int inf = 1e6;
const int cont = 1e18;
using namespace std;

void solve(){
    int n, ans;
    cin>>n;
    ans = n/11;
    bool f = 0;
    if(ans%2)f = 1;
    ans*=2;
    n%=11;
    if(f){
     if(n>5)ans+=2;
    else if(n) ans += 1;
    }
    else{
    if(n>6)ans+=2;
    else if(n) ans += 1;
    }
    cout<<ans<<endl;
}

int32_t main() {
   Fast;

   solve();
    return Okay;
}



Measured memory_bytes: 3636