akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
        
    int n,k;
    cin>>n>>k;
    int ar[n+1];
    repa(i,1,n)
        cin>>ar[i];
    bool vis[n+1]={0};
    int cur = 1;
    vector<int>sequence;

    while(!vis[cur])
    {
        sequence.pb(cur);
        vis[cur] = true;
        cur = ar[cur];
    }
    int lst = cur;
    sequence.pb(cur);

    if ( k<=sequence.size()-1 )
        cout<<sequence[k]<<endl;
    else
    {
        k-=sequence.size();

        vector<int>recur;
        bool found = false;
        for (auto it:sequence)
        {
            if (found)
                recur.pb(it);

            if (it==lst)
            {
                found = true;
                continue;
            }
        }
        cout<<recur[ k%(recur.size()) ]<<endl;
    }

}

Measured memory_bytes: 8068
#include<bits/stdc++.h>
using namespace std;
int MOD = 1e9+7;
int main()
{
	int h, w;
	cin>>h>>w;
	char mat[h][w];
	long long dp[h+1][w+1];
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin>>mat[i][j];

	memset(dp, 0, sizeof(dp));
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		{
			if(mat[i][j] == '.'){
				if(i == 0 && j == 0)
					dp[i][j] = 1;
				else if(i == 0)
					dp[i][j] += dp[i][j-1];
				else if(j == 0)
					dp[i][j] += dp[i-1][j];
				else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
			}
			
		}
	cout<<dp[h-1][w-1];
}

Measured memory_bytes: 9088
a,b,c,d = map(int, raw_input().split(' '))

def gcd(a,b):
	#a = bk + r
	if b == 0: return a
	return gcd(b, a % b)

def lcm(a,b):
	return a*b/gcd(a,b)

# how many multiples of c among integers between a and b inclusive
def f(a,b,c):
	if a == 0:
		return b/c + 1
	return b/c  - (a-1)/c 

print b -a + 1 - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d))

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

string S;

int main(){
    cin>>S;
    int w=0,b=0;

    for(int i=0;i<S.size();i++){
        if(i%2==0){
            if(S[i]=='0')w++;
            else b++;
        }
        else{
            if(S[i]=='1')w++;
            else b++;
        }
    }
    cout<<min(w,b)<<endl;

}

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

using namespace std;

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = a * (n / (a + b));

  ll div = n % (a + b);
  if (div < a) {
    ans += div;
  }
  else
  {
    ans += a;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const ll INF = 0x3f3f3f3f;

int a[13][13];
int p[13];

bool check(int mask, int n)
{
    int o=0, i=1;
    while(mask>0)
    {
        if(mask&1)
        {
            if(a[n][i]) o++;
        }
        mask >>= 1;
        i++;
    }
    if(o%2==p[n]) return 1;
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    int n, m, ans=0;
    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        cin >> a[i][0];
        for(int j=0; j<a[i][0]; j++)
        {
            int x;
            cin >> x;
            a[i][x]=1;
        }
    }
    for(int i=1; i<=m; i++) cin >> p[i];
    for(int i=0; i<(1<<n); i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(!check(i, j))
                goto ski;
        }
        ans++;
        ski:;
    }
    cout << ans;
}


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

int main() {
    int s[3];
    int w;
    for(int & i : s){
        cin >> i;
    }

    sort(rbegin(s), rend(s));

    w = s[0] * 10;
    cout << w+s[1]+s[2] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
ll LCM(ll x, ll y);

int main() {
	ll A, B, C, D, E, sum;
	cin >> A >> B >> C >> D;

	sum = 0;

	E = LCM(C, D);
	sum += B / C;
	sum -= (A - 1) / C;
	sum += B / D;
	sum -= (A - 1) / D;
	sum += (A - 1) / E;
	sum -= B / E;

	cout << B - A + 1 - sum;

	return 0;
}

ll LCM(ll x, ll y) {
	ll a,b,r, gcd, lcm;

	a = max(x, y);
	b = min(x, y);
	r = 1;

	while (r != 0) {
		r = a % b;
		if (r == 0) {
			gcd = b;
		}
		a = b;
		b = r;
	}

	lcm = x * y / gcd;

	return lcm;
}

Measured memory_bytes: 3140
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int N, P, A, even = 0, odd = 0;
	long long int out;
	cin >> N >> P;
	for (int i = 0; i < N; i++) {
		cin >> A;
		if (A % 2 == 0) even++;
		else odd++;
	}
	if (odd != 0) out = pow(2, N - 1);
	else if (P == 0) out = pow(2, N);
	else out = 0;
	cout << out << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main main = new Main();
		int A[] = new int[100]; // sufficient
		int N = sc.nextInt();
		for (int i = 0; i < N; ++i)
			A[i] = sc.nextInt();
		int swapcnt = main.selectionSort(A, N);
		for (int i = 0; i < N; ++i) {
			// to join A by " "(space).
			if (i > 0) System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(swapcnt);
	}
	/* sort array A(size: N) by using Selection Sort. */
	/* return counts of swapping. */
	public int selectionSort(int A[], int N) {
		int swapcnt = 0;
		for (int i = 0; i < N; ++i) {
			// assume index pointing min{A} is i.
			int minj = i;
			// linear search for index pointing min{A}.
			for (int j = i; j < N; ++j) {
				if (A[j] < A[minj])
					minj = j;
			}
			// not swap when i == minj.
			if (i == minj)
				continue;
			// swapping A[i] for A[minj](i != minj).
			int tmp = A[i];
			A[i] = A[minj];
			A[minj] = tmp;
			++swapcnt;
		}
		return swapcnt;
	}
}


Measured memory_bytes: 26420
N = int(input())
word_list = []
word_old = input()
word_list.append(word_old)
flag = 0
for i in range(1, N):
    word = input()
    if word[0] != word_old[-1] or word in word_list:
        print("No")
        flag = 1
        break
    word_old = word
    word_list.append(word_old)

if flag == 0:
    print("Yes")

Measured memory_bytes: 3064
/**
 *      purpose : ARC 81 D
 *      author  : kyomukyomupurin
 *      created : 2018-10-31 17:07:20
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

const int MOD = 1e9 + 7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; string S1, S2; cin >> N >> S1 >> S2;

    int end = 0;
    vector<int> count;
    while (end < N){
        if (S1[end] == S1[end + 1]) {
            count.push_back(2); end += 2;
        }
        else {
            count.push_back(1); ++end;
        }
    }
    /*
    for (int i = 0; i < (int) count.size(); ++i){
        print(count[i]);
    }
    */
    int64 ans;
    if (count[0] == 1) ans = 3;
    else ans = 6;

    for (int i = 1; i < (int) count.size(); ++i) {
        if (count[i - 1] == 1 && count[i] == 1) {
            ans *= 2; ans %= MOD;
        }
        else if (count[i - 1] == 1 && count[i] == 2){
            ans *= 2; ans %= MOD;
        }
        else if (count[i - 1] == 2 && count[i] == 2){
            ans *= 3; ans %= MOD;
        }
    }
    print(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int A,B,C,D;
int main(){
  cin >> A >> B >> C >> D;
  if((A + B) > (C + D)){
    cout << "Left" << endl;
  }
  else if((A + B) < (C + D)){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll n;

void solve(){
    cin >> n;
    unordered_set<string> s;
    string t;
    while(n--){
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 17736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,n,a,i,ans,dif = 10000000;scanf("%d%d",&x,&n);
  bool s[102] = {};
  for(i=0;i<n;i++){
    scanf("%d",&a);s[a] = 1;
  }
  for(i=0;i<=101;i++){
    if(!s[i] && abs(i-x)<dif){
      ans = i;dif = abs(i-x);
    }
  }
  printf("%d\n",ans);
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
  
  if(a==b){
    cout<<"YES"<<endl;
    return 0;
  }
  
  ll d=abs(a-b);
  ll s=w-v;
  
  if(v<=w){
    cout<<"NO"<<endl;
    return 0;
  }
  
  if(d-(v*t-w*t)<=0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll n, a, b;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n >> a >> b;

	if ((n == 1 && a != b) || a > b) {
		cout << 0 << endl;
		return 0;
	}
	cout << a + b * (n - 1) - (a * (n - 1) + b) + 1 << endl;
	return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long long N,sum=0;
    cin>>N;
    for (long int i=1;i<=N;i++){
        if (i%3!=0&&i%5!=0) sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
//#include <unordered_map>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<x<<endl
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//::iterator it;
inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
int h,w,k;
char a[10][10];
bool check(int x,int y){
	int p=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if((x&(1<<i))||(y&(1<<j)))continue;
			if(a[i][j]=='#')p++;
		}
	}
	if(p==k)return true;
	else return false;
}
int main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>h>>w>>k;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){
    	cin>>a[i][j];
    }
    int ans=0;
    for(int i=0;i<(1<<h);i++){
    	for(int j=0;j<(1<<w);j++){
    		if(check(i,j))ans++;
    	}
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/

 
 

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

int main(){
    int N;
    cin >> N;
    int h[N];
    rep(i, N){
        cin >> h[i];
    }
    int dp[N];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    // rep(i, N){
    //     printf("%d\n", dp[i]);
    // }
    printf("%d\n", dp[N-1]);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int N,i,j,k,v;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	/*print*/
	for(i=0;i<N;i++){
		printf("%d",A[i]);
		if(i<N-1){
			printf(" ");
		}
	}
	printf("\n");
	/*insertion sort*/
	for(i=1;i<=N-1;i++){
		v = A[i];
		j = i - 1;
		while(j>=0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		/*print*/
		for(k=0;k<N;k++){
			printf("%d",A[k]);
			if(k<N-1){
				printf(" ");
			}
		}
		printf("\n");
	}
    return 0;
}


Measured memory_bytes: 2084
#include<iostream>

using namespace std;

int main(){
  int K, N;
  cin >> K >> N;
  int A[N];
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }

  int d = 0;
  for (int i = 0; i < N - 1; i++){
    if(d < A[i+1] - A[i]){
      d = A[i+1] - A[i];
    }
  }

  if(d < (K - A[N-1] + A[0])){
      d = K - A[N-1] + A[0];
  }

  printf("%d\n", K - d);
}


Measured memory_bytes: 4544
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef set <int> se;
#define endl "\n"
#define for(i,a,b) for(int i = a;i<b;i++)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int MOD = 1e9+7;
long long mod(long long x){
    return ((x%MOD + MOD)%MOD);
}
long long add(long long a,long long b){
    return mod(mod(a)+mod(b));
}
long long mul(long long a,long long b){
    return mod(mod(a)*mod(b));
}
long long sub(long long a,long long b){
    return mod(mod(a)-mod(b));
}

ll power(ll a,ll b){
    if(b==0) return 1;
    if (b==1) return a%MOD;
    ll res = 1;
    while(b>0){
        if(b%2!=0) res =mul(res,a);
        a = mul(a,a);
        b = b/2;

    }
    return res;

}

void solve(){
    ll n;
    cin>>n;
    ll t;
    if(n==1) {cout<<0<<endl;return;}
    if (n==2) {cout<<2<<endl;return;}
    t = sub(add(power(10LL,n),power(8LL,n)),mul(2LL,power(9LL,n)));
    cout<<t;
}
 
 
int main()
{

solve();
 
return 0;
}

Measured memory_bytes: 3616
n = gets.to_i
cnt = Array.new(10){Array.new(10, 0)}
1.upto(n) do |i|
  cnt[i.to_s[0].to_i][i % 10] += 1
end
ans = 0
10.times do |i|
  10.times do |j|
    ans += cnt[i][j] * cnt[j][i]
  end
end
puts ans

Measured memory_bytes: 1788
I=lambda:map(int,input().split())
N=0xfffff
n,q=I()
c=list(I())
Q=[]
R=range
for i in R(q):l,r=I();Q.append(l<<40|r<<20|i)
Q.sort()
A=[[n]for i in R(N)]
for i in R(n)[::-1]:A[c[i]].append(i)
B=[0]*N
def P(i,x):
	i+=1
	while i<=n:B[i]+=x;i+=i&-i
for i in A:P(i[-1],1)
t=0
o=[0]*q
for x in Q:
	l=(x>>40)-1
	r=x>>20&N
	i=x&N
	while t<l:
		b=A[c[t]]
		P(b[-1],-1)
		b.pop()
		P(b[-1],1)
		t+=1
	while r:o[i]+=B[r];r-=r&-r
	while l:o[i]-=B[l];l-=l&-l
for i in o:print(i)

Measured memory_bytes: 249596
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll A=0, B=0, t, n;std::cin >> n;
  vll a(n);
  re(i, n) std::cin >> a[i];
  multiset<ll> s;
  re(i, n){
    std::cin >> t;
    ll k = a[i]-t;
    if(k>0) B+=k;
    else{
      k *=-1;
      if(k%2==1) A+=k/2+1, B++;
      else A+=k/2;
    }
  }
  if(A>=B) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

signed main() {
	IOS;
	int n, m;
	cin >> n >> m;
	if(n&1){
		for(int i = 1; i <= m; i++)
			cout << i << " " << n-i << endl;
	}	
	else{
		int x = (m+1)/2;
		for(int i = 1; i <= min(x, m); i++)
			cout << i << " " << n-i+1 << endl;
		for(int i = x+1; i <= m; i++)
			cout << i << " " << n-i << endl;
 	}
	return 0;
}

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

int main(){
  int ans = 0, N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  
  for(int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i);
  
  vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, 0));

  for(int i = 0; i < N; i++){
    for(int j = 1; j <= W; j++){
      if(j - w.at(i) >= 0){
        dp.at(i + 1).at(j) = max(dp.at(i).at(j), dp.at(i).at(j - w.at(i)) + v.at(i));
      }else{
        dp.at(i + 1).at(j) = dp.at(i).at(j);
      }
    }
  }
  
 
  cout << dp.at(N).at(W) << endl;
}

Measured memory_bytes: 80256
import itertools

N = int(input())
L = list(map(int, input().split()))

unqL = list(set(L))
Lnums = {}
for l in unqL:
    Lnums[l] = L.count(l)

cnt = 0    
for cmb in itertools.combinations(unqL, 3):
    cmb = sorted(cmb)
    l1, l2, lmax = cmb    
    if l1 + l2 > lmax:
        cnt += Lnums[l1] * Lnums[l2] * Lnums[lmax]
    
print(cnt)


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
} //三項演算子を使ったgcd(最大公約数)

bool ck_honest(int bit, int N, vector<vector<pair<int, int>>> vec)
{

    for (int i = 0; i < N; i++)
    {
        if (!(bit & (1 << i)))
            continue;
        for (auto p : vec[i])
        {
            int x = p.first;
            int y = p.second;
            if (y == 1 && !(bit & (1 << x)))
                return false;

            if (y == 0 && (bit & (1 << x)))
                return false;
        }
    }

    return true;
}

int main()
{
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> vec(N + 1);
    rep(i, N)
    {
        int a;
        cin >> a;
        vec[i].resize(a);
        rep(j, a)
        {
            int x, y;
            cin >> x >> y;
            vec[i][j] = make_pair(x, y);
            vec[i][j].first--;
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        if (ck_honest(bit, N, vec))
        {
            int count = 0;
            for (int i = 0; i < N; ++i)
            {
                if (bit & (1 << i))
                    ++count;
            }
            ans = max(ans, count);
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int N,sum = 0;
  cin >> N;
  string X;
  vector<string> s(N);
  vector<int> t(N);
  for (int i = 0; i < N; i++){
    cin >> s.at(i) >> t.at(i);
    sum += t.at(i);
  }
  cin >> X;
  for (int i = 0; i < N; i++){
    sum -= t.at(i);
    if (s.at(i) == X) break;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int n;
    cin >> n;
    if(n%1000==0){
        cout << 0 << endl;
        return 0;
    }
    cout << 1000-n%1000 << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,l,r) for(int i=(l);i<(r);i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}    

template<typename T>
T lcm(T a, T b){
    return a/gcd(a,b)*b;
}    
// g++ -std=c++11 prac.cpp 

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    ll x=0,y=0,z=0,n,m=0,k,ans=0,h,w,sum=0,Max=-1e9-1,cnt=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n;
    VL a(n),b(n),c(n);
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    rep(i,n){
        cin >> b[i];
        cnt += b[i];
    }
    if(sum > cnt){
        cout << "No" << endl;
        return 0;
    }
    x = cnt - sum;
    rep(i,n){
        if (a[i]<b[i]){
            y = b[i]-a[i];
            z += (y+1)/2;
        }
    }
    if(x >= z){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
K=int(input())
S=input()
n=K+len(S)
MAX=2000000
fac=[0]*MAX
finv=[0]*MAX
inv=[0]*MAX
MOD=10**9+7
#テーブルを作る前処理
def COMinit():
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,MAX):
      fac[i] = fac[i-1] * i % MOD
      inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
      finv[i] = finv[i - 1] * inv[i] % MOD

#二項係数計算
def comb(n,k):
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  else:
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

COMinit()
com=1
q=(26**K)%(10**9+7)
ans=0
for i in range(K+1):
  ans+=(q*comb(len(S)+i-1,i))%(10**9+7)#comb(len(S)+i-1,len(S)-1))%(10**9+7)
  q=(q*423076927)%(10**9+7)
  #com=(com*(len(S)+i))//(i+1)
print(ans%(10**9+7))
#print((25*576923081)%(10**9+7))

Measured memory_bytes: 127380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll 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 (ll 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(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,m,k;
    cin>>n>>m>>k;
    COMinit();
    ll ans = 0;
    for(ll i=0;i<m;i++){
        ll ret = COM(n*m-2,k-2) * n;
        ret %= mod;
        ll sum = (m-1-i) * (m-i) / 2;
        sum %= mod;
        sum += (i*(i+1)/2)%mod;
        sum %= mod;
        sum *= n;
        sum %= mod;
        ret *= sum;
        ret %= mod;
        ans += ret;
        ans %= mod;
    }
    for(ll i=0;i<n;i++){
        ll ret = COM(n*m-2,k-2) * m;
        ret %= mod;
        ll sum = (n-1-i) * (n-i) / 2;
        sum %= mod;
        sum += (i*(i+1)/2)%mod;
        sum %= mod;
        sum *= m;
        sum %= mod;
        ret *= sum;
        ret %= mod;
        ans += ret;
        ans %= mod;
    }
    ans *= modinv(2);
    ans %= mod;
    cout << ans << endl;
    
}

Measured memory_bytes: 12160
import sys
sys.setrecursionlimit(10**6)
n=int(input())
path=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    path[u-1].append((v-1,w%2))
    path[v-1].append((u-1,w%2))
ans=[0]+[-1]*(n-1)
def dfs(i):
    global n,path,ans
    for j in path[i]:
        if ans[j[0]]==-1:
            if j[1]:
                ans[j[0]]=1-ans[i]
                dfs(j[0])
            else:
                ans[j[0]]=ans[i]
                dfs(j[0])
dfs(0)
print("\n".join(map(str,ans)))

Measured memory_bytes: 76376
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int h[100005];
	int cost[100005];
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	cost[0] = 0;
	cost[1] = abs(h[1]-h[0]);
	if(n==2){
		cout << cost[1] << endl;
		return 0;
	}
	for(int i=2;i<n;i++){
		int a = cost[i-2]+abs(h[i]-h[i-2]);
		int b = cost[i-1]+abs(h[i]-h[i-1]);
		cost[i] = min(a,b);
	}
	cout << cost[n-1] << endl;	
	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	ll N, TM; cin >> N >> TM;
	vl T(N); FOR(i, 0, N) cin >> T[i];

	ll ans = TM;

	FOR(i, 1, N) {
		if (T[i] < T[i - 1] + TM) {
			ans += TM - (T[i - 1] + TM - T[i]);
		}
		else {
			ans += TM;
		}
	}

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[100001];
vector<int>v;
int main(void){
	int n;
	int k;
	cin>>n>>k;
	int i;
	int x,y;
	for(i=0;i<n;i++)	cin>>a[i];
	int cnt=0;
	for(i=0;i<n-1;i++){
		x=a[i];
		x++;
		y=a[i+1]-x;
		//cout<<y<<endl;
		if(y!=0)	v.push_back(y);
	}
	sort(v.begin(),v.end());
	int m=v.size()-(k-1);
	int sum=n;
	//cout<<m<<endl;
	for(i=0;i<m;i++){
		sum+=v[i];
	}
	cout<<sum<<endl;
	return 0;
}
	
		


Measured memory_bytes: 3940
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

const uint64_t MOD = 1000 * 1000 * 1000 + 7;

template <uint8_t max_value, uint8_t mod_value>
struct index_mod {
  uint8_t mod[max_value];
  constexpr index_mod() : mod() {
    for (size_t i = 0; i < max_value; ++i) {
      mod[i] = i % mod_value;
    }
  }
};

template <uint8_t mod_value>
struct sub_index {
  uint8_t index[mod_value][mod_value - 10];
  constexpr sub_index() : index() {
    auto value = 0;
    uint8_t in[mod_value] = {0};
    for (size_t i = 0; i < mod_value; ++i) {
      value += 10;
      for (size_t j = 0; j < mod_value - 10; ++j) {
        // index[i][j] = (value + j) % mod_value;
        auto v = (value + j) % mod_value;
        index[v][in[v]] = i;
        ++in[v];
      }
    }
  }
};

int main() {
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin >> s;

  // i番目の文字を見た時に13との剰余がnになる個数を数え上げる
  std::vector<uint64_t> dp(2 * 13);

  constexpr index_mod<13 * 10, 13> imod;
  constexpr sub_index<13> sindex;

  // for (size_t i = 0; i < 13; ++i) {
  // for (size_t j = 0; j < 3; ++j) {
  //   std::cout << (int)sindex.index[i][j] << ",";
  // }
  // std::cout << std::endl;
  // }

  uint64_t row_sum = 0;

  {  // テーブル初期化
    int val = -1;
    if (s[0] != '?') val = s[0] - '0';
    if (val == -1) {
      for (size_t i = 0; i < 10; ++i) {
        dp[i % 13] = 1;
      }
      row_sum = 10;
    } else {
      dp[val % 13] = 1;
      row_sum = 1;
    }
    // % 13は不要だけど定義に帰るため
  }

  for (size_t i = 1, e = s.length(); i < e; ++i) {
    int val = -1;
    if (s[i] != '?') val = s[i] - '0';
    if (val == -1) {
      auto temp_sum = row_sum + 3 * MOD;
      for (size_t here = 0; here < 13; ++here) {
        uint64_t no_need = 0;
        for (size_t j = 0; j < 3; ++j) {
          no_need += dp[sindex.index[here][j]];
        }
        dp[13 + here] = temp_sum - no_need;
      }
    } else {
      for (size_t pre = 0; pre < 13; ++pre) {
        dp[13 + imod.mod[pre * 10 + val]] = dp[pre];
      }
    }

    //     for (int i = 0; i < 2; ++i) {
    //     for (int j = 0; j < 13; ++j) {
    //       std::cout << dp[i * 13 + j] << ",";
    //     }
    //     std::cout << std::endl;
    //   }
    //
    row_sum = 0;
    for (size_t i = 0; i < 13; ++i) {
      dp[i] = dp[13 + i] % MOD;
      row_sum += dp[13 + i];
      // dp[i] = dp[13 + i];
      dp[13 + i] = 0;
    }
    row_sum %= MOD;
  }

  std::cout << dp[5] % MOD << "\n";
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 998244353
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {

    ll N,K; cin>>N>>K;

    if(K*2-1>N){
        cout<< -1 <<"\n"; return;
    }

    ll a[N],b[N],c[N];

    rep(i,N){
        c[i]=K+N*2+i;
    }

    if(N%2==0){
        rep(i,N/2){
            a[i]=K+2*i;
            b[i]=K+N*3/2-1-i;
        }
        rep(i,N/2){
            a[i+N/2]=K+2*i+1;
            b[i+N/2]=K+N*2-1-i;
        }
    }
    else{
        rep(i,(N+1)/2){
            a[i]=K+2*i;
            b[i]=K+N*3/2-i;
        }
        rep(i,(N-1)/2){
            a[i+(N+1)/2]=K+2*i+1;
            b[i+(N+1)/2]=K+N*2-1-i;
        }
    }

    rep(i,N){
        cout<< a[i]<< " "<<  b[i]<< " "<< c[i] <<"\n";
    }


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

pair<int, int> toPr(int v) {
    int fst = 0;
    int r = v;
    while (r > 0) {
        fst = r;
        r /= 10;
    }
    return {fst, v%10};
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    map<pair<int, int>, int> cnt;
    for (int i = 1; i <= n; i++) {
        cnt[toPr(i)]++;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        auto pr = toPr(i);
        ans += cnt[{pr.second, pr.first}];
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    int n;
    cin>>n;
    int a[n+1],b[n+1],count=0;
    for(int i=1;i<=n;i++)a[i] = i;
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++){
        if(a[i] != b[i]){
            count++;
        }
    }
    if(count == 0 || count == 2){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 10000;
const int MOD = 1000000000 + 7;

struct Matrix
{
	int n, m, v[3][3];
	void print()
	{
		cerr << n << ' '<< m << endl;
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < m; j++)
				cerr << v[i][j] << ' ';
			cerr << endl;
		}
		cerr << endl;
	}
};

const Matrix UNIT = {3, 3, {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}};
const Matrix INIT = {3, 1, {{1}, {0}, {0}}};
const Matrix COMM = {3, 3, {{2, 1, 1}, {2, 1, 0}, {1, 1, 1}}};
const Matrix SPEC = {3, 3, {{1, 0, 0}, {2, 1, 0}, {1, 1, 1}}};
const Matrix ANSW = {1, 3, {{1, 1, 1}}};

Matrix operator * (const Matrix &a, const Matrix &b)
{
	Matrix ret = {a.n, b.m};
	for(int i = 0; i < ret.n; i++)
		for(int j = 0; j < ret.m; j++)
			for(int k = 0; k < a.m; k++)
				ret.v[i][j] = (ret.v[i][j] + (long long)a.v[i][k] * b.v[k][j]) % MOD;
	return ret;
}

Matrix fpow(const Matrix &a, long long p)
{
	Matrix ret = UNIT, cur = a;
	for(; p; p >>= 1, cur = cur * cur)
		if(p & 1)
			ret = ret * cur;
	return ret;
}

int n, m, p[MAXN];


int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= m; i++)
		cin >> p[i];
	p[0] = 0, p[m + 1] = n - 1;

	Matrix cur = UNIT;

	for(int i = 1; i <= m; i++)
	{
		cur = cur * fpow(COMM, p[i] - p[i - 1] - 1);
		cur = cur * SPEC;
	}
	cur = cur * fpow(COMM, p[m + 1] - p[m]);
	cur = cur * INIT;
	cur = ANSW * cur;
	// cur.print();

	int ans = cur.v[0][0];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
n = int(input())
c = input()
l_c = len(c)
r = 0
ans = 0

for i in range(l_c):
    if c[i] == 'R':
        r += 1

for i in range(r,l_c):
    if c[i] == 'R':
        ans += 1

print(ans)


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

typedef long long ll;

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    ans += (x % 500) / 5 * 5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
h,w = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
#print(ar)
l = np.zeros((h,w),dtype=int)
r = np.zeros((h,w),dtype=int)
u = np.zeros((h,w),dtype=int)
d = np.zeros((h,w),dtype=int)

for i in range(h):
  u[i] = (u[i-1]+1)*ar[i]
  #print(u)
  d[-i-1] = (d[-i]+1)*ar[-i-1]
  #print(d)
  
for j in range(w):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  #print(l)
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
  #print(r)
print(np.max(u+d+l+r)-3)

Measured memory_bytes: 219796
import java.util.Scanner;

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

		while (true) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			if (h == 0 && w == 0) {
				break;
			}
			char[][] map = new char[h][w];
			boolean[][] loop = new boolean[h][w];
			for (int i = 0; i < h; i++) {
				map[i] = scanner.next().toCharArray();
			}

			int x = 0;
			int y = 0;
			loop: while (true) {
				if (loop[y][x]) {
					System.out.println("LOOP");
					break;
				}
				loop[y][x] = true;
				switch (map[y][x]) {
				case '>':
					x++;
					break;
				case '<':
					x--;
					break;
				case '^':
					y--;
					break;
				case 'v':
					y++;
					break;
				default:
					System.out.println(x + " " + y);
					break loop;
				}
			}
		}

	}

}

Measured memory_bytes: 21884
word = str(input())
wlist = []
for i in word:
    wlist.append(i)
n = int(input())
for i in range(n):
    com = list(input().split())
    a = int(com[1])
    b = int(com[2])
    if (com[0] == 'print'):
        for k in range(a, b + 1):
            print(wlist[k], end ='')
        print()
    elif (com[0] == 'reverse'):
        decoy = []
        for k in range(a, b+1):
            decoy.append(wlist[b+a-k])
        for l in range(b-a+1):
            wlist[a+l] = decoy[l]
    elif (com[0] == 'replace'):
        p = str(com[3])
        plist = []
        for k in p:
            plist.append(k)
        for l in range(b-a+1):
            wlist[a+l] = plist[l]
            


Measured memory_bytes: 5760
N = int(input())
s = {}
count = 0
for i in range(N):
    a = input()
    if a not in s:
        s[a] = 1
        count += 1
    elif s[a] % 2:
        s[a] += 1
        count -= 1
    else:
        s[a] += 1
        count += 1


print(count)

Measured memory_bytes: 17884
# ABC113C - ID
import sys
input = sys.stdin.readline

def main():
    N, M = tuple(map(int, input().split()))
    P = [[] for _ in range(N + 1)]  # prefectures
    for num in range(M):  # classify cities by prefectures
        pref, year = tuple(map(int, input().split()))
        P[pref] += [(year, num)]
    ans = [""] * M
    P = (sorted(p) for p in P)  # sort by year
    for pref_idx, pref in enumerate(P):
        for city_idx, (_, num) in enumerate(pref, 1):
            x = "{:06}{:06}".format(pref_idx, city_idx)
            ans[num] = x
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 34584
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
int a[1000];
int main()
{
	IO;
	memset(a,0,sizeof(a));
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int tmp;
		cin>>tmp;
		for(int j=0;j<tmp;j++){
			int tt;
			cin>>tt;
			a[tt]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=a[i];
	}
	cout<<n-ans<<endl;
 	return 0;
}







Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) ;
        a = (a * a) ;

        
        b >>= 1;
    }
    res;
    return res;
}
void solve(){
    ll n,t;
    cin>>n>>t;
    ll a[n+1];
    for(int i= 1;i<=n;i++){
        cin>>a[i];
    }   
    ll ans = 0;
    a[0]=0;
    for(int i= 1;i<=n;i++){
        ans += min(t,a[i]-a[i-1]);
    }
    cout<<ans+t<<endl;
}






int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;


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

  int n;
  cin >> n;
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
    cout << "hon\n";
  } else if (n == 0 || n == 1 || n == 6 || n == 8) {
    cout << "pon\n";
  } else if (n == 3) {
    cout << "bon\n";
  }

}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
vector<long> l;

long f(long x){
    if(l[x] != 0) return l[x];
    if(x == 0){
        return l[0] = 2;
    }else if(x == 1){
        return l[1] = 1;
    }else{
        return l[x] = f(x - 1) + f(x - 2);
    }
}
int main(void){
    long n;
    cin >> n;
    l.resize(86);
    cout << f(n) << endl;
    
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        Long h = sc.nextLong();
        Long w = sc.nextLong();
        if(h == 1 || w == 1) {
            System.out.println(1); 
            return;
            
        }
        System.out.println((h * w + 1) / 2);
        
    }
}


Measured memory_bytes: 35672
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())

MOD = int(1e9+7)
S = input()

dp  = [ [0] * 4  for _ in range(len(S)+1)]

dp[0][0] = 1
for e,s in enumerate(S,1):

    dp[e][0] = dp[e-1][0] * (3 if s == "?" else 1)

    if s == "A" or s == "?":
        dp[e][1] += dp[e-1][0] 
    dp[e][1] += dp[e-1][1] * (3 if s == "?" else 1) 

    if s == "B" or s == "?":
        dp[e][2] += dp[e-1][1]
    dp[e][2] += dp[e-1][2] * (3 if s == "?" else 1)

    if s == "C" or s == "?":
        dp[e][3] += dp[e-1][2]
    dp[e][3] += dp[e-1][3] * (3 if s == "?" else 1)


    for i in range(4):
        dp[e][i] %= MOD



    # dp[i,0] = 1
    # dp[i][1] = dp[i-1][0]* if s == "A" or "?"


print(dp[len(S)][3] % MOD)




Measured memory_bytes: 54764
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int dyy[]={0,-1,0,1};
int dxx[]={-1,0,1,0};

//#define int ll

int n,m;
int a[1001],b[1001],c[1001];
int d[1001][1001];
int dd[1001][1001];
int cnt;

void warshall_floyd(int n){
  rep(i,0,n)rep(j,0,n)rep(k,0,n){
    if(d[j][k]>d[j][i]+d[i][k] )d[j][k]=d[j][i]+d[i][k];
  }
}

signed main(){
    cin>>n>>m;
    rep(i,0,1000)rep(j,0,1000){
        if(i!=j)d[i][j]=1<<28;
        else d[i][j]=0;
    }
    rep(i,0,m){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--,b[i]--;
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
        dd[a[i]][b[i]]=dd[b[i]][a[i]]=c[i];
    }
    warshall_floyd(n);
    
    cnt=0;
    rep(i,0,n){
        rep(j,i+1,n){
            if(dd[i][j]>d[i][j])cnt++;
        }
    }
    
    cout<<cnt<<endl;
    
    return 0;
}

Measured memory_bytes: 6400
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.ff == b.ff) {
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff);
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;

    return res;
}
int findlcm(int arr[], int n) 
{ 
    // Initialize result 
    int ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (__gcd(arr[i], ans))); 
  
    return ans; 
}
bool prime[100001];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}

//Define mx for maximum range and MOD for large numbers
#define mx 100004
#define MOD 1000000007;
// Declare all the variables and global functions here - 
int n,m;
int oc[mx] = {0};
int32_t main()
{
    IOS;
 //    #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
	// #endif
    /********************* From here **********************/
    
    cin >> n >> m;
    int mini  = -1, maxi = inf;
    rep(i, 0, m){
    	int l,m;
    	cin >> l >>m;
    	mini = max(mini, l);
    	maxi = min(maxi, m);
    }
    if(maxi >= mini)
    	cout << maxi - mini+1 << endl;
    else
    	cout << 0 << endl;

    
}

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

#define oo       1e9
#define ll       long long
#define sc(x)    scanf("%d",&x)
#define sz(x)    (int)x.size()
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()
#define F        first
#define S        second
#define pi       acos(-1)
#define EPS      1e-12

int n;
int arr[1010];
int ans;

int main() {
#ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  sc(n);
  n*=2;
  for(int i=0;i<n;i++)
    sc(arr[i]);
  sort(arr,arr+n);
  for(int i=0;i<n;i+=2)
    ans+=arr[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 256