akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#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 all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define SZ(x) (int)x.size()
#define e_b emplace_back
using ll = long long;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct LazySegmentTree{
	int n;
	vector<ll> node,lazy;
	vector<bool> lazyFlag;
	
	LazySegmentTree(int sz){
		n=1;
		while(sz>n) n<<=1;
		node.assign(2*n,0);
		lazy.assign(2*n,0);
		lazyFlag.assign(2*n,false);
	}
	
	void eval(int k,int l,int r){
		if(lazyFlag[k]){
			node[k]=lazy[k];
			if(r-l>1){
				lazy[2*k]=lazy[k]/2;
				lazyFlag[2*k]=true;
				lazy[2*k+1]=lazy[k]/2;
				lazyFlag[2*k+1]=true;
			}
			lazy[k]=0;
			lazyFlag[k]=false;
		}
	}
	
	void update(int a,int b,ll x,int k=1,int l=0,int r=-1){
		if(r<0) r=n;
		eval(k,l,r);
		if(r<=a||b<=l) return;
		if(a<=l&&r<=b){
			lazy[k]=(r-l)*x;
			lazyFlag[k]=true;
			eval(k,l,r);
		}
		else{
			update(a,b,x,2*k,l,(l+r)/2);
			update(a,b,x,2*k+1,(l+r)/2,r);
			node[k]=node[2*k]+node[2*k+1];
		}
	}
	
	ll getSum(int a,int b,int k=1,int l=0,int r=-1){
		if(r<0) r=n;
		eval(k,l,r);
		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return node[k];
		ll vl=getSum(a,b,2*k,l,(l+r)/2);
		ll vr=getSum(a,b,2*k+1,(l+r)/2,r);
		return vl+vr;
	}
};

int main(){
	int n,q; cin>>n>>q;
	LazySegmentTree tree(n);
	rep(i,q){
		int m,s,t,x;
		cin>>m;
		if(m==0){
			cin>>s>>t>>x;
			tree.update(s,t+1,x);
		}else{
			cin>>s>>t;
			cout<<tree.getSum(s,t+1)<<endl;
		}
	}
}

	



Measured memory_bytes: 7084
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

long long n;

int main()
{
    cin>>n;
    long long ans=n-1;
    for(long long i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            long long b=n/i;
            ans=min(ans,b-1+i-1);
         }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;


ll add(ll a,ll b){
    return (a+b) % MOD;
}

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

    vector<int> a(m);
    for(int i=0; i<m; i++){
        cin >> a[i];
    }
    ll dp[n+1];
    for(int i=0; i<n+1; i++) dp[i] = 0;
    for(int i=0; i<m; i++){
        dp[a[i]] = -1;
    }
    dp[0] = 1;
    // for(int i=1; i<n+1; i++){
    //     if(dp[i]!=-1){
    //         dp[i] = 1;
    //         break;
    //     }
    // }

    for(int i=1; i<n+1; i++){
        if(dp[i] == -1) continue;        
        if(dp[i-1] != -1){
            dp[i] = add(dp[i], dp[i-1]);
        }
        if(i>1 && dp[i-2] != -1){
            dp[i] = add(dp[i], dp[i-2]);
        }
    }
    cout << dp[n] % 1000000007 << endl;
    // for(int i=0; i<n+1; i++){
    //     cout << dp[i] << endl;
    // }

    return 0;
}

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

using namespace std;

int main(){
	int w, h;
	cin>>h>>w;
	char field[h][w];
	int ans[h][w];

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin>>field[h - 1 - i][w - 1 - j];
		}
	}
	ans[0][0] = 0;
	if (field[0][0] == '#') ans[0][0] = 1;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if ((i == 0) && (j == 0)) continue;
			int add1 = 0;
			int add2 = 0;
			if(field[i][j] == '#'){
				if (j > 0){
					if (field[i][j - 1] == '.') add1++;
				}
				if(i > 0){
					if (field[i - 1][j] == '.') add2++;
				}
			}
			if (j > 0) ans[i][j] = ans[i][j - 1] + add1;
			if (i > 0) ans[i][j] = ans[i - 1][j] + add2;
			if ((i > 0) && (j > 0)) ans[i][j] = min(ans[i][j - 1] + add1, ans[i - 1][j] + add2);
		}
	}
	cout<<ans[h - 1][w - 1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFL = 2e18;
const int MOD = 1000000007;
int main(){
	int x;
	cin >> x;
	cout << (x + 1) % 2 << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#define rad 60*M_PI/180.0
typedef struct{
  double x;
  double y;
}coordinate;
void koch(int,coordinate,coordinate);
int main(){
  int n;
  coordinate p1;
  coordinate p2;
  p1.x=p1.y=p2.y=0.0;
  p2.x=100.0;
  scanf("%d",&n);
  printf("%f %f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  return 0;
}
void koch(int n,coordinate p1,coordinate p2){
  coordinate s,u,t;
  s.x=(2*p1.x+p2.x)/3.0;
  s.y=(2*p1.y+p2.y)/3.0;
  t.x=(p1.x+2*p2.x)/3.0;
  t.y=(p1.y+2*p2.y)/3.0;
  u.x=(t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
  u.y=(t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;
  if(n==0)return;
  koch(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  koch(n-1,t,p2);
}



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

ll sum;
ll floor(ll b_, ll n_){
    if(n_ < b_) return n_;
    else{
        return floor(b_, n_/b_) + n_ % b_;
    }
}

int main(){
    ll n, mem, sum, s, memb;
    cin >> n >> s;

    if(n == s){
        cout << n+1 << endl;
        return 0;
    }

    for(ll i = 2; i <= sqrt(n)+1; i++){
        if(s == floor(i, n)){
            cout << i << endl;
            return 0;
        }
    }

    if(n-s > 1){
        for(ll i = sqrt(n); i > 0; i--){
            if(s == floor((n-s)/i+1, n)){
                cout << (n-s)/i+1 << endl;
                return 0;
            }
        }
    }
   
    cout << "-1\n";

}

Measured memory_bytes: 256
n = int(input())

ans = []
for i in range(2,n+1):
  if n %i == 0:
    ans.append(i)
  if i *i > n:
    break

if len(ans) == 0:
  print(n -1)
else:
  print(ans[-1] + int(n / ans[-1]) -2)

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

using namespace std;

int main() {

	string s;
	cin >> s;

	int yea;
	yea = stoi(s.substr(0,4));
	int mon;
	mon = stoi(s.substr(5, 2));
	int da;
	da = stoi(s.substr(8, 2));

	if (yea < 2019) { cout << "Heisei" << endl; return 0; }
	if (yea > 2019) { cout << "TBD" << endl;  return 0;}
	if (yea == 2019 && mon < 4) { cout << "Heisei" << endl; return 0;
	}
	if (yea == 2019 && mon > 4) { cout << "TBD" << endl; return 0;
	}
	if (yea == 2019 && mon == 4 && da<=30) { cout << "Heisei" << endl;  return 0;
	}

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    int k;
    cin >> s >> k;
    int sl = s.length();
    int fc = 0, lc = 0, cc = 0, nc = 0;
    bool bf = false;
    ll ans = 0;
    
    rep(i, sl) {
        if (s[0] == s[i]) {
            fc++;
        }
        else {
            break;
        }
    }
    
    rrep(i, sl) {
        if (s[0] == s[i]) {
            lc++;
        }
        else {
            break;
        }
    }
    
    if (fc == sl) {
        ans = (ll)sl * k / 2;
    }
    else {
        rep(i, sl - 1) {
            if ((!bf) && (s[i] == s[i + 1])) {
                cc++;
                bf = true;
            }
            else {
                bf = false;
            }
        }
        
        if ((fc % 2 == 1) && (lc % 2 == 1)) {
            nc++;
        }
        
        ans = (ll)cc * k + (ll)nc * (k - 1);
    }
    
    cout << ans << endl;
    return 0;
}

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

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

#define REPR(i,n) for(int i =n; i >=0; --i)

#define _REP(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

using namespace std;
long long ans = 0;

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

   vector<int> b(n-1); 

    REP(i,n-1)cin >> b[i];

    ans += b[0];

    _REP(i,1,n-1){
        ans += min(b[i],b[i-1]);
    }

    ans += b[n-2];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,t;
  cin >> n >> x >> t;
  if(n%x==0){
    cout << (n/x)*t;
  }
  else{
    cout << ((n/x)+1)*t;
  }
  return 0;
}

Measured memory_bytes: 3636
a,b,c,d = map(int,input().split())
if c%b ==0:
  e = c//b
else:
  e = c//b +1

if a%d ==0:
  f = a//d
else:
  f = a//d +1

if e>f:
  print("No")
else:
  print("Yes")

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

int main(){
  string A;
  string B;
  cin >> A;
  cin >> B;
  
  if(A.size() > B.size())
    cout << "GREATER";
  if(A.size() < B.size())
    cout << "LESS";
  if(A.size() == B.size()){
    for(int i=0;i<A.size();i++){
      if(A[i]>B[i]){
        cout << "GREATER";
        return 0;
      }
      else if(A[i]<B[i]){
        cout << "LESS";
        return 0;
      }
    }
    cout << "EQUAL";
  }
  return 0;
}

Measured memory_bytes: 3624
using System;

namespace AISingProgrammingContest2019A_BulletinBoard
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int h = int.Parse(Console.ReadLine());
            int w = int.Parse(Console.ReadLine());

            int h_num_streets = n - h + 1;
            int w_num_streets = n - w + 1;

            int result = h_num_streets * w_num_streets;

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 11092
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        mut A: usize,
        mut B: usize,
        mut C: usize,
    }

    std::mem::swap(&mut A, &mut B);
    std::mem::swap(&mut A, &mut C);

    println!("{} {} {}", A, B, C);
}


Measured memory_bytes: 2112
#include<stdio.h>
main()
{
  int A,B,C;
  scanf("%d%d",&A,&B);
  C=A*B;
  if(A<=9 && B<=9){
    printf("%d",C);
  }
  if(10<=A || 10<=B){
    printf("%d",-1);
  }
  return 0;
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m=0;
    int z=0;
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
        if(a[i]<0){
            m++;
        }else if(a[i]==0){
            z++;
        }
    }
    ll ans = 0;
    ll mi = INF;
    REP(i,n){
        ll tmp = abs(a[i]);
        ans+=tmp;
        mi = min(mi,tmp);
    }
    if(z==0&&m%2==1){
        ans-=mi*2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

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

    int N;
    cin >> N;
    for(int i=0; i<=N; i+=4){
        for(int j=0; j<=N; j+=7){
            if(i+j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    
    return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    int len = s.size(), cnt = 0;
    for(int i = 0; i < len; i++)
    {
        if(s[i] != t[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3916
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int k = s.nextInt();
		int[][] peeledTile = new int[k][2];
		int center = n / 2 + 1;
		for(int i = 0; i < k; i++){

			peeledTile[i][0] = s.nextInt();
			peeledTile[i][1] = s.nextInt();

		}

		for(int i = 0; i < k; i++){

			if(peeledTile[i][0] > n / 2){
				peeledTile[i][0] = n - peeledTile[i][0] + 1;
			}
			if(peeledTile[i][1] > n / 2){
				peeledTile[i][1] = n - peeledTile[i][1] + 1;
			}

			if(n % 2 == 1 && peeledTile[i][0] == center && peeledTile[i][1] == center){
				print(center % 3);
			}else if(peeledTile[i][0] % 3 == peeledTile[i][1] % 3 || peeledTile[i][0] < peeledTile[i][1]){
				print(peeledTile[i][0] % 3);
			}else{
				print(peeledTile[i][1] % 3);
			}

		}

		s.close();

	}

	public static void print(int ans){
		if(ans == 0)
			ans = 3;
		System.out.println(ans);
	}
}

Measured memory_bytes: 35092
#include <stdio.h>

int main(void){
  int a[3], i, sum=0;
  for(i=0; i<3; i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }

  if(sum>=22){
    printf("bust\n");
  }
  else if(sum<=21){
    printf("win\n");
  }

  return 0;
}


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

using namespace std;

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

	long long w, h, x, y;
	cin >> w >> h >> x >> y;

	long double area = (w * h) / 2.0;
	cout << fixed << setprecision(10) << area << ' ';

	if(w == 2 * x and h == 2 * y) {
		cout << 1;
	}
	else {
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 123456
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

int main()
{	
	ll a, b;
	fin(a); fin(b);
	if(a >= 13)
	{
		fout(b);
		exit(0);
	}
	if(a >= 6 && a <= 12)
	{
		fout(b / 2);
		exit(0);
	}
	if(a <= 5)
	{
		fout(0LL);
		exit(0);
	}
	return 0;
}


Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())
room = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    room[a-1].append(b)
    room[b-1].append(a)

point = [0 for i in range(n)]
d = deque([0])

while len(d) > 0:
    p = d.popleft()
    for v in room[p]:
        if point[v-1] == 0:
            d.append(v-1)
            point[v-1] = p+1

print('Yes')
for i in range(1, n):
    print(point[i])


Measured memory_bytes: 37472
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){

    int N,M;
    long long ans=1;

    cin >> N >> M;

    if(abs(N-M)>=2){
        cout << 0 << endl;
        return 0;
    }
    
    for(int i=1;i<=N;i++){
        ans = ans * i % 1000000007;
    }

    for(int i=1;i<=M;i++){
        ans = ans * i % 1000000007;
    }

    if(N==M){
        ans = ans * 2;
    }
    ans = ans % 1000000007 ;

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
        char input[1300];
        scanf("%[^\n]",input,stdin);
        int i=0;
        char c;
        while(c=input[i++]) {
                if('a'<=c and c<='z') {
                        printf("%c",c-'a'+'A');
                }
                else if('A'<=c and c<='Z') {
                        printf("%c",c-'A'+'a');
                }
                else{
                        printf("%c",c);
                }
        }
        printf("\n");
        return 0;
}



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

int n, p, ans[100005];
deque<int> q, q2[100005];

int main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++){
    scanf("%d",&p);
    q2[p-1].push_back(i+1);
  }
  
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      
      while(!q2[j].empty()){
	q.push_front(q2[j].back());
	q2[j].pop_back();
      }
      
      if(ans[j]==0&&!q.empty()){
	ans[j]=q.front();
	q.pop_front();
      }
      
    }
  }
  
  for(int i=0;i<n;i++) cout<<ans[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 70948
from bisect import bisect_left as bl
def dist(p1,p2): return abs(p1-p2)
INF = 10**18
a,b,q = map(int,input().split())
S = [-INF]+[int(input()) for _ in range(a)]+[INF]
T = [-INF]+[int(input()) for _ in range(b)]+[INF]
X = [int(input()) for _ in range(q)]

for i in range(q):
    ans = INF
    s = bl(S,X[i])
    t = bl(T,X[i])
    p = ((s,t),(s-1,t-1))
    for ps,pt in p:
        if dist(X[i],S[ps]) < dist(X[i],T[pt]):
            pt = bl(T,S[ps])
            ans = min(ans , dist(X[i],S[ps])+min(dist(S[ps],T[pt]),dist(S[ps],T[pt-1])))
        else:
            ps = bl(S,T[pt])
            ans = min(ans , dist(X[i],T[pt])+min(dist(T[pt],S[ps]),dist(T[pt],S[ps-1])))
    print(ans)

Measured memory_bytes: 16152
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4] == s[5])
		cout<<"Yes\n";
	else cout<<"No\n";

	return 0;	
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef unsigned long long ull;


int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    int N = s.length();
    
    int result = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) { // g
            if (s[i] == 'p') {
                result -= 1;
            }
        } else {
            if (s[i] == 'g') {
                result += 1;
            }
        }
    }
    cout << result << endl;

    return 0;
}


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

const int MAX = 1000001; 
struct Query 
{ 
    int l, r, idx; 
}; 

bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 

void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 

int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                    query(queries[query_counter].r + 1, bit, n)- 
                    query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 

int main() 
{ 
    int n,q,x,y;
    cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    Query queries[q];
    for(int i=0;i<q;i++){
        cin>>x>>y;
        x--;y--;
        queries[i].l=x;
        queries[i].r=y;
        queries[i].idx=i;
    }
    sort(queries, queries+q, cmp); 
    answeringQueries(arr, n, queries, q); 
    return 0; 
} 


Measured memory_bytes: 19324
import numpy as np

N, Q = (int(x) for x in input().split())

dic = {}

for i in range(N-1) :
    #a, b = (int(x) for x in input().split())
    a, b = map(int,input().split())
    dic[b] = a

#SUM = np.zeros(N, dtype=np.int)
SUM = [0]*N

for i in range(Q) :
    #p, x = (int(x) for x in input().split())
    p, x = map(int,input().split())
    SUM[p-1] = SUM[p-1] + x

for i in range(N-1) :
    SUM[i+1] += SUM[dic.get(i+2)-1]

print(' '.join(map(str, SUM)))


Measured memory_bytes: 62820
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include<string>
#include<cstring>
#include<complex>
#include<cmath>
using namespace std;
#define rep(i, n)   for(int i = 0; i < (int)(n); i++)
#define mpp(i,j,k)  make_pair((int)(i),make_pair((int)(j),(int)(k)))
typedef pair<int,pair<int,int > > pp;
typedef vector<int> vi;
typedef vector<vi>  vvi;
int n,m,a,b,c;
vvi e(100,vi(100,1000000));
vvi d(100,vi(100,-1));



int main(){

cin>>n>>m;
rep(i,m)cin>>a>>b>>c,e[a-1][b-1]=c,e[b-1][a-1]=c,d[a-1][b-1]=c;
rep(i,n)e[i][i]=0;
rep(k,n)rep(i,n)rep(j,n)e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
int cc=0;
rep(i,n)rep(j,n)if(e[i][j]==d[i][j])cc+=1;


cout<<m-cc<<endl;

  return 0;}




Measured memory_bytes: 384
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())

# # # # # # # # # # # # # # # # # # # # # # # # #

class Dice:
    pip = [0 for i in xrange(6)]

    def __init__(self, arg):
        self.pip = arg

    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip

    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")

dice = Dice(list_input(int))

for i in xrange(input()):
    a, b = list_input(int)

    while dice.pip[0] != a:
        if dice.pip[2] != a and dice.pip[3] != a:
            dice.roll("N")
        else:
            dice.roll("N")
            dice.roll("W")
            dice.roll("S")

    while dice.pip[1] != b:
        dice.roll("N")
        dice.roll("W")
        dice.roll("S")

    print dice.pip[2]

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
double factorial(int n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

double dist(pair<int,int> a,pair<int,int> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    string s;
    cin>>s;
    for(ll i=0;i<s.size();i++){
        cout<<"x";
    }
    cout<<endl;

    
    
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

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

int main(){
	int N,W;
	cin>>N>>W;
	vector<ip> item(N);
	rep(i,N)cin>>item[i].first>>item[i].second;
	vector<vector<int>> dp(N+1, vector<int> (W+1, 0));
	for(int i = N-1; i>=0; --i){
		for(int j = 1; j<=W; ++j){
			if(item[i].second > j){
				dp[i][j] = dp[i+1][j];
			}else{
				chmax(dp[i][j], dp[i+1][j]);
				chmax(dp[i][j], dp[i][j-item[i].second] + item[i].first);
			}
		}
	}
	cout<<dp[0][W]<<endl;
	return 0;
}


Measured memory_bytes: 6836
N = int(input())
A = list(map(int, input().split(' ')))
A = sorted(A)
A = A[::-1]

first_second_biggest_numpairs = []

flag = False
for i in range(N):
    if flag == True:
        flag = False
        continue
    if i + 1 < N:
        if A[i] == A[i + 1]:
            if len(first_second_biggest_numpairs) < 2:
                first_second_biggest_numpairs.append(A[i])
                flag = True
            else:
                break
            
if len(first_second_biggest_numpairs) == 2:
    print(str(first_second_biggest_numpairs[0] * first_second_biggest_numpairs[1]))
else:
    print("0")


Measured memory_bytes: 14252
N, Y = map(int, input().split())
ans = 0
for a in range(N+1):
    for b in range(N+1-a):
        c = N - a -b
        if (10000*a+5000*b+1000*c) == Y:
            ans += 1
            print(str(a) + ' ' + str(b) + ' ' + str(c))
            break
    else:
        continue
    break
if ans == 0:
    print(str(-1) + ' ' + str(-1) + ' ' + str(-1))

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] h = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			System.out.println(getResult(h, 0, n - 1, 0));
		}
	}

	/**
	 * 条件を満たすような最小の「水やり」操作の回数を計算する
	 * 
	 * @param h       希望する高さの配列
	 * @param from    処理対象indexのfrom
	 * @param to      処理対象indexのfrom
	 * @param current 現在の高さ
	 * @return
	 */
	private static int getResult(final int[] h, int from, int to, int current) {
		if (from > to) {
			return 0;
		}
		if (from == to) {
			return h[from] - current;
		}
		List<Integer> minIndexes = new ArrayList<>();
		int min = Integer.MAX_VALUE;
		// 最小値とそのindexを計算する
		for (int i = from; i <= to; i++) {
			if (min > h[i]) {
				minIndexes.clear();
				min = h[i];
				minIndexes.add(i);
			}
		}
		int answer = 0;
		int prev = from - 1;
		for (int index : minIndexes) {
			answer += getResult(h, prev + 1, minIndexes.get(0) - 1, min);
			prev = index;
		}
		answer += getResult(h, prev + 1, to, min);
		return answer + min - current;
	}
}


Measured memory_bytes: 36360
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

char buf[100000+10];

int main(void) {
  scanf("%s", buf);
  int n = strlen(buf);
  REP(i, n) {
    if(i+1 < n && buf[i] == buf[i+1]) {
      printf("%d %d\n", i+1, i+2);
      return 0;
    } else if(i+2 < n && buf[i] == buf[i+2]) {
      printf("%d %d\n", i+1, i+3);
      return 0;
    }
  }

  puts("-1 -1");
  
  return 0;
}


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;
int mod = 1000000007;

void solve();

int main(void){
    int H, W, N; cin >> H >> W >> N;
    int sx, sy; cin >> sx >> sy;
    string S, T; cin >> S >> T;

    vector<int> U(N, 0), D(N, 0), R(N, 0), L(N, 0);
    rep(i, N){
        if(i == 0){
            if(S[0] == 'U') U[0]++;
            else if(S[0] == 'D') D[0]++;
            else if(S[0] == 'R') R[0]++;
            else L[0]++;
            continue;
        }
        switch(S[i]){
            case 'R':
                R[i] = R[i-1]+1;
                L[i] = L[i-1];
                U[i] = U[i-1];
                D[i] = D[i-1];
                break;
            case 'L':
                R[i] = R[i-1];
                L[i] = L[i-1]+1;
                U[i] = U[i-1];
                D[i] = D[i-1];
                break;
            case 'U':
                R[i] = R[i-1];
                L[i] = L[i-1];
                U[i] = U[i-1]+1;
                D[i] = D[i-1];
                break;
            case 'D':
                R[i] = R[i-1];
                L[i] = L[i-1];
                U[i] = U[i-1];
                D[i] = D[i-1]+1;
                break;
            default:
                break;
        }
    }

    vector<pair<int, int>> tate(N+1);
    vector<pair<int, int>> yoko(N+1);
    tate[0] = make_pair(sx, sx);
    yoko[0] = make_pair(sy, sy);
    rep(i, N){
        switch(T[i]){
            case 'R':
                tate[i+1] = tate[i];
                yoko[i+1] = make_pair(yoko[i].first, min(W+L[i], yoko[i].second+1));
                break;
            case 'L':
                tate[i+1] = tate[i];
                yoko[i+1] = make_pair(max(1-R[i], yoko[i].first-1), yoko[i].second);
                break;
            case 'U':
                tate[i+1] = make_pair(max(1-D[i], tate[i].first-1), tate[i].second);
                yoko[i+1] = yoko[i];
                break;
            case 'D':
                tate[i+1] = make_pair(tate[i].first, min(H+U[i], tate[i].second+1));
                yoko[i+1] = yoko[i];
                break;
            default:
                break;
        }
    }
    //iターン後に終了するには、任意のtate[i].first以上tate[i].second以下の数について
        //または任意のyoko[i].first以上yoko[i].second以下の数について
        //外に出れるか判定する必要がある
        //縦方向で考えると
        //iターン目までにUがK回 -> 押し出せるのはK以下の区間
        //iターン目までにDがL回 -> 押し出せるのは(H+1)-L以上の区間
        //これら二つの区間によってtate[i]がカバーされるなら取り除ける
        //カバーされるとき: 2つの区間に重なりがあるまたは片方の区間がtate[i]の全てをカバーするとき
    rep(i, N){
        //U[i]以下または(H+1)-D[i]以上の区間内に入っているなら取り除ける
        //cout << "tate: " << tate[i].first << " " << tate[i].second << endl;
        //cout << "yoko: " << yoko[i].first << " " << yoko[i].second << endl;
        if(tate[i].second <= U[i] || (H+1)-D[i] <= tate[i].first
        || yoko[i].second <= L[i] || (W+1)-R[i] <= yoko[i].first){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

void solve(){}

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

def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

MOD = 10**9+7
N = int(input())
F = []
zero_v = 0
inf = 0
zero = 0
for _ in range(N):
  x,y = map(int,input().split())
  if x==0 and y==0:
    zero_v += 1
  elif x==0:
    inf += 1
  elif y==0:
    zero += 1
  else:
    G = gcd(abs(x),abs(y))
    F.append((x//G,y//G))

all_keys = set()

for x,y in F:
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))
  x,y = -y,x
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))

all_dic = {k:[0,0] for k in all_keys}

for x,y in F:
  if x*y > 0:
    if x>0:
      all_dic[(x,y)][0] += 1
    else:
      all_dic[(-x,-y)][0] += 1
  else:
    if x>0:
      all_dic[(-y,x)][1] += 1
    else:
      all_dic[(y,-x)][1] += 1

ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1
ans %= MOD

for k in all_keys:
  P,N = all_dic[k]
  ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1
  ans %= MOD


ans += zero_v-1

print(ans%MOD)

Measured memory_bytes: 158840
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    l, r, d = map(int, input().split())
    graph[l-1].append((r-1, d))
    graph[r-1].append((l-1, -d))
seen = [False]*n
dist = [None]*n
for i in range(n):
    if seen[i]:
        continue
    q = deque([i])
    dist[i] = 0
    while q:
        node = q.popleft()
        if seen[node]:
            continue
        seen[node] = True
        for c_node, d in graph[node]:
            if dist[c_node] is None:
                dist[c_node] = dist[node] + d
            elif dist[c_node] != dist[node] + d:
                print('No')
                exit(0)
            q.append(c_node)
print('Yes')

Measured memory_bytes: 71528
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int a, b, c;
        a = input.nextInt();
        b = input.nextInt();
        c = input.nextInt();
        int min = Math.min(a, Math.min(b, c));
        int max = Math.max(a, Math.max(b, c));
        System.out.print(min);
        if (a != min && a != max) System.out.print(" " + a + " ");
        else if (b != min && b != max) System.out.print(" " + b + " ");
        else System.out.print(" " + c + " ");
        System.out.println(max);
    }         
}

Measured memory_bytes: 17228
fun main(args: Array<String>) {
    a98(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a98(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (a, b) = args[0].split(" ").map { it.toInt() }
    println(listOf(a + b, a - b, a * b).max())
}


Measured memory_bytes: 38136
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()
ans = 0
# ary[i]:B[i]より小さいAの要素の数
ary = [0]*len(B)

for i, b in enumerate(B):
    if A[0] >= b:
        continue
    left = 0
    right = len(A)
    while right-left > 1:
        middle = (left+right)//2
        if A[middle] >= b:
            right = middle
        else:
            left = middle
    ary[i] = left+1
    if i != 0:
        ary[i] += ary[i-1]
for i, c in enumerate(C):
    if B[0] >= c:
        continue
    left = 0
    right = len(B)
    while right-left > 1:
        middle = (left+right)//2
        if B[middle] >= c:
            right = middle
        else:
            left = middle
    ans += ary[left]

print(ans)


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

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

    int ans = 1;

    for(int i = 0; i < n; i++){
        if(i == 0){
            ans *= k;
        }else{
            ans *= (k - 1);
        }
    }
    
    cout << ans << endl;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  if (s.back() == 's') {
    s += "es";
  } else {
    s += 's';
  }
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n||m){
    vector<int> tate(n+1,0),yoko(m+1,0);
    map<int,int> tatec,yokoc;
    for(int i=1,p,q=0;i<=n;++i){
      cin>>p;q+=p;
      tate[i]=q;
    }
    for(int i=1,p,q=0;i<=m;++i){
      cin>>p;q+=p;
      yoko[i]=q;
    }
    for(int i=0;i<n;++i) for(int j=i+1;j<=n;++j) ++tatec[tate[j]-tate[i]];
    for(int i=0;i<m;++i) for(int j=i+1;j<=m;++j) ++yokoc[yoko[j]-yoko[i]];
    int ans=0;
    for(map<int,int>::iterator it=tatec.begin();it!=tatec.end();++it){
      if(yokoc.find(it->first)!=yokoc.end()) ans+=(it->second)*(yokoc[it->first]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int n,k,q;
int ans=2e9;
vector<int> a;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>k>>q;
    a.resize(n);
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }

    for (int x: a) {
	multiset<int> s;
	vector<int> v;
	for (int i=0; i<=n; i++) {
	    if (i==n||a[i]<x) {
		sort(v.rbegin(), v.rend());
		while ((int)v.size() >= k) {
		    s.insert(v.back());
		    v.pop_back();
		}
		v.clear();
	    } else {
		v.push_back(a[i]);
	    }
	}
	if ((int)s.size()<q) continue;
	auto iter=s.begin();
	for (int j=0; j<q-1; j++) iter++;
	ans=min(ans,*iter-x);
    }
    cout<<ans<<endl;  

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;


int main() {
 long long int a,b,c,d[100010],e[100010];
  
  cin >> a ;
  
  for(int i=0;i<a;i++)
   cin >> e[i] ;
   
  c =0;
  
  for(int i=0;i<a;i++){
    for(int j=i+1;j<a;j++){
      c += e[i]*e[j];
    }
  }
  
  cout << c << endl;
}

Measured memory_bytes: 256
mod stdin_reader {
  use std::io::stdin;
  use std::io::Read;

  pub struct StdinReader {
    pub buf: Vec<String>,
    pub cursor: usize,
  }

  pub fn new() -> StdinReader {
    StdinReader::new()
  }

  impl StdinReader {
    pub fn new() -> Self {
      let mut s = String::new();
      let stdin = stdin();
      stdin.lock().read_to_string(&mut s).unwrap();
      let buf = s.split_whitespace().map(|s| s.to_string()).collect();
      return StdinReader { buf: buf, cursor: 0 }
    }

    pub fn read_all(&self) -> Vec<String> {
      return self.buf.clone()
    }

    pub fn next(&mut self) -> Option<String> {
      let val = self.buf.get(self.cursor).cloned();
      self.cursor += 1;
      return val
    }

    pub fn as_i64(&mut self) -> Option<i64> {
      self.next().and_then(|s| s.parse::<i64>().ok())
    }

    pub fn as_f64(&mut self) -> Option<f64> {
      self.next().and_then(|s| s.parse::<f64>().ok())
    }

    pub fn as_usize(&mut self) -> Option<usize> {
      self.next().and_then(|s| s.parse::<usize>().ok())
    }
  }
}

fn is_int(n: f64) -> bool {
  let trunc = (n.trunc() as i64) as f64;
  return (n - trunc) < 0.0001
}

fn main() {
  let mut reader = stdin_reader::new();
  let n = reader.as_usize().unwrap();
  let d = reader.as_usize().unwrap();

  let points: Vec<Vec<f64>> = (0..n).map(|_| {
    (0..d).map(|_| reader.as_f64().unwrap()).collect()
  }).collect();

  let mut cnt = 0;
  for i in 0..n {
    for j in (i+1)..n {
      let distance = points[i].clone().into_iter().zip(points[j].clone().into_iter())
                      .map(|(l, r)| (l - r)*(l-r))
                      .fold(0.0, |sum, cur| sum + cur)
                      .sqrt();
      if is_int(distance) {
        cnt += 1
      }
    }
  }
  println!("{}", cnt);
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((b-a)==(c-b)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define ll long long
using namespace std;
ll  fun(int n,int W,ll dp[][100001],int *v,int *w)
{
    ///base case
    if(W<=0 || n==0)
    {
        return 0;
    }

    //look up
    if(dp[n][W]!=0)
    return dp[n][W];

   if((W-w[n])>=0)
     {
         dp[n][W]=max(fun(n-1,W-w[n],dp,v,w)+v[n],fun(n-1,W,dp,v,w));
     }
    else
    dp[n][W]=max(dp[n][W],fun(n-1,W,dp,v,w));
   
    return dp[n][W];
}
 void solve(int n,int W,int *v,int *w )
 {    
     ll dp[n+1][100001];
     for(int i=0;i<=n;i++)
     {
         for(int j=0;j<=W;j++)
         {
             dp[i][j]=0;
         }
     }
     cout<<fun(n,W,dp,v,w)<<endl;
 }
int main()
{  
    int n,W;
    cin>>n>>W;
    int w[101];
    int v[101];
    for(int i=1;i<=n;i++)
      cin>>w[i]>>v[i];
   
   solve(n,W,v,w);

    
    return 0;
}

Measured memory_bytes: 82464
#include <iostream>
#define ll long long

using namespace std;

int main() {
    ll n;
    cin >> n;
    ll A = 0;
    ll B = 0;
    ll C = 0;
    ll D = 0;
    for (ll i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AC") {
            A++;
        } else if (s == "WA") {
            B++;
        } else if (s == "TLE") {
            C++;
        } else {
            D++;
        }        
    }
    cout << "AC x " << A << '\n';
    cout << "WA x " << B << '\n';
    cout << "TLE x " << C << '\n';
    cout << "RE x " << D << '\n';
    return 0;
}

Measured memory_bytes: 3608
#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>



using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next (int u){
    for (int v = nt[u]; v<n;v++){
        nt[u] = v+1;
        if(M[u][v]){
            return v;
        }
    }
    return -1;
}

void dfs_visit(int r){
    for (int i=0;i<n;i++){
        nt[i] = 0;
    }
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        if(v != -1){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    for (int i=0;i<n;i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    for (int u=0;u<n;u++){
        if (color[u] == WHITE){
            dfs_visit(u);
        }
    }
    for (int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}
int main(){
  

    int u,k,v;
    cin >> n;
    for (int i=0;i<n;i++){
        for (int j= 0;j<n;j++){
            M[i][j] = 0;
        }
    }
    for (int i = 0;i<n;i++){
        cin >> u >> k;
        u--;
        for (int j=0;j<k;j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

}


Measured memory_bytes: 3120
#include <iostream>
#include <numeric>
#include <algorithm>

using namespace std;

long long N, L;
long long a[100005];

int main()
{
    cin >> N >> L;

    for (int i = 0; i < N;i++)
    {
        cin >> a[i];
    }

    int p = -1;

    for (int i = 0; i < N - 1;i++)
    {
        if(a[i] + a[i + 1] >= L)
        {
            p = i;
            break;
        }
    }

    if(p == -1)
    {
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;

    for (int i = 0; i < p;i++)
    {
        cout << i + 1 << endl;
    }
    for (int i = N - 2; p <= i; i--)
    {
        cout << i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        x: usize,
        v: [(usize, [usize; m]); n]
    }
    let mut ans = usize::max_value();
    for i in 0..1 << n {
        let mut c = 0;
        let mut l = vec![0; m];
        for j in 0..n {
            if i & 1 << j == 0 {
                continue;
            }
            c += v[j].0;
            for k in 0..m {
                l[k] += v[j].1[k];
            }
        }
        if l.iter().all(|&y| y >= x) {
            ans = min(ans, c);
        }
    }
    if ans == usize::max_value() {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<string, int> freq;
    string s;
    rep(i, N)
    {
        cin >> s;
        sort(s.begin(),s.end());
        freq[s]++;
    }
    ll ans = 0;

    for (auto v : freq)
    {
        ll num = v.second;
        if (num > 1)
        {
            ans += (num * (num - 1)) / 2;
        }
    }
    cout << ans << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;

void solve(){
    char a[1];
    cin >> a;
    cout << ++a[0] << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 256