akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int n, W, v[110], w[110], dp[100010];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> n >> W;
  rep(i,n) cin >> v[i] >> w[i];
  rep(i,n) {
    rep(j,W+1) {
      if(j+w[i] <= W) chmax(dp[j+w[i]], dp[j]+v[i]);
    }
  }
  int ans = dp[W];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3260
#include <math.h>
#include <bits/stdc++.h>//一括で読み込み
typedef long long ll;
using namespace std;

int main() 
{
    ll n;
    ll a,b,c;
    cin >> n;

    ll changes[6];
    for(int i = 0; i < 2; i++)
    {
      cin >> a >> b >> c;
	    changes[i*3+0] = a;
      changes[i*3+1] = b;
      changes[i*3+2] = c;
    }

    ll memo = 0;
    ll m = n;
    for(int i = 0; i <= n; i++)
    {
      for(int j = 0; j <= n-i; j++)
      {
        memo = n;
        if(changes[0*3+0] < changes[1*3+0])
        {
          memo += changes[1*3+0]*(i/changes[0*3+0]) - i/changes[0*3+0]*changes[0*3+0];
        }
        if(changes[0*3+1] < changes[1*3+1])
        {
          memo += changes[1*3+1]*(j/changes[0*3+1]) - j/changes[0*3+1]*changes[0*3+1];
        }
        if(changes[0*3+2] < changes[1*3+2])
        {
          memo += changes[1*3+2]*((n-i-j)/changes[0*3+2]) - (n-i-j)/changes[0*3+2]*changes[0*3+2];
        }
        m = fmax(m,memo);
      }
    }
    n = m;
    m = n;

    if(changes[0*3+0] < changes[1*3+0])
    {
      for(int i = 0; i <= n; i++)
      { 
        memo = n;
        if(changes[1*3+1] < changes[0*3+1])
        {
          memo += changes[0*3+1]*(i/changes[1*3+1]) - i/changes[1*3+1]*changes[1*3+1];
        }
        if(changes[1*3+2] < changes[0*3+2])
        {
          memo += changes[0*3+2]*((n-i)/changes[1*3+2]) - (n-i)/changes[1*3+2]*changes[1*3+2];
        }
        m = fmax(m,memo);
      }
    }else if(changes[0*3+1] < changes[1*3+1])
    {
      for(int i = 0; i <= n; i++)
      { 
        memo = n;
        if(changes[1*3+0] < changes[0*3+0])
        {
          memo += changes[0*3+0]*(i/changes[1*3+0]) - i/changes[1*3+0]*changes[1*3+0];
        }
        if(changes[1*3+2] < changes[0*3+2])
        {
          memo += changes[0*3+2]*((n-i)/changes[1*3+2]) - (n-i)/changes[1*3+2]*changes[1*3+2];
        }
        m = fmax(m,memo);
      }
    }else if(changes[0*3+2] < changes[1*3+2])
    {
      for(int i = 0; i <= n; i++)
      { 
        memo = n;
        if(changes[1*3+1] < changes[0*3+1])
        {
          memo += changes[0*3+1]*(i/changes[1*3+1]) - i/changes[1*3+1]*changes[1*3+1];
        }
        if(changes[1*3+0] < changes[0*3+0])
        {
          memo += changes[0*3+0]*((n-i)/changes[1*3+0]) - (n-i)/changes[1*3+0]*changes[1*3+0];
        }
        m = fmax(m,memo);
      }
    }else
    {
      for(int i = 0; i <= n; i++)
      {
        for(int j = 0; j <= n-i; j++)
        {
          memo = n;
          if(changes[1*3+1] < changes[0*3+1])
          {
            memo += changes[0*3+1]*(i/changes[1*3+1]) - i/changes[1*3+1]*changes[1*3+1];
          }
          if(changes[1*3+0] < changes[0*3+0])
          {
            memo += changes[0*3+0]*(j/changes[1*3+0]) - j/changes[1*3+0]*changes[1*3+0];
          }if(changes[1*3+2] < changes[0*3+2])
          {
            memo += changes[0*3+2]*((n-i-j)/changes[1*3+2]) - (n-i-j)/changes[1*3+2]*changes[1*3+2];
          }
          m = fmax(m,memo);
        }
      }
    }
    cout << m << endl;
	}


Measured memory_bytes: 256
IMPLICIT NONE
INTEGER :: n, record_n, m = 0

READ*, n

record_n = n

DO
    m = m + MOD(n,10)
    n = n / 10
    if( n == 0 ) then
        exit
    end if
END DO

IF (mod(record_n,m) == 0) THEN
    PRINT*, "Yes"
ELSE
    PRINT*, "No"
END IF

END

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



int main() {
  
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int b[n]={};
  int cnt=0;
  int bb[n];
  for(int i=n;i>0;i--){
    int c=0;
    for(int j=i+i;j<=n;j+=i){
      c+=b[j-1];
    }
    if(c%2!=a[i-1]){
      b[i-1]=1;
      bb[cnt]=i;
      cnt++;
    }else{b[i-1]=0;}
  }
  cout<<cnt<<endl;
  for(int i=cnt-1;i>=0;i--){
    cout<<bb[i]<<" ";
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 2944
N, M = map(int, input().split())
a = list(map(int, input().split()))
s = 0
ss = {0: 1}
for n in a:
    s += n
    ss[s % M] = ss.get(s % M, 0) + 1
ans = 0
for n in ss.values():
    if n > 1:
        ans += n * (n - 1) // 2
print(ans)


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
  	for (int j = 0; j < W; j++) {
    	cin >> data.at(i).at(j);
    }
  }
  
  bool a = true;
  int num = 0;
  for (int i = 0; i < H; i++) {
  	for (int j = 0; j < W; j++) {
      if (data.at(i).at(j) == '.') continue;
      
      for (int k = -1; k <= 1; k++) {
        if (i + k == -1 || i + k == H) continue;
      	for (int l = -1; l <= 1; l++) {
          if (j + l == -1 || j + l == W) continue;
          if (k * l != 0) continue;
          if (data.at(i + k).at(j + l) == '#') num++;
        }
      }
      
      if (num == 1) a = false;
      num = 0;
    }
  }
  if (a == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3600
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long

int main() {
  int N;
  cin >> N;
  vector<long long> v(N, 0);
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    v[a]++;
  }

  long long ans = 1;

  //偶数なら初期値1、奇数なら初期値0
  for (int i = (N % 2 == 0) ? 1 : 0; i < N; i += 2) {
    //奇数で0が一つじゃ無い時と、数値が2以外の時
    if ((i == 0 && v[0] != 1) || (i != 0 && v[i] != 2)) {
      ans = 0;
      break;
    } else
      ans = ans * v[i] % 1000000007;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> l(2*n);
  for(int i=0; i<2*n; i++)cin>>l.at(i);

  sort(l.begin(), l.end());
  int ans=0;
  for(int i=0; i<n; i++)ans+=l.at(2*i);
  cout<<ans<<endl;
}

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

int main() {
  int h=0;
  string S;
  cin >> S;
  int size = (int)(S.length());
  
  if(size==2){
    if(S[0]==S[1]) cout<<"1 2"<<endl;
    else cout << "-1 -1" << endl;
    return 0;
  }
  
  
  else{
  for(int i=0;i<size-2;i++){
    if(S[i]==S[i+1]){
      cout << i+1 << " " << i+2;
      h=1;
      break;
    }
    else if(S[i]==S[i+2]){
      cout << i+1 << " " << i+3;
      h=1;
      break;
    }
  }
  
  if(h==0) cout << "-1 -1" << endl;
  }
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int n[] = {a,b,c};
		Arrays.sort(n);
		int num1 = (n[2]-n[0])/2;
		int num2 = (n[2]-n[1])/2;
		if(n[0]%2==n[1]%2 && n[1]%2==n[2]%2)System.out.println(num1+num2);
		else if(n[0]%2==n[1]%2 && n[1]%2!=n[2]%2)System.out.println(num1+num2+1);
        else System.out.println(num1+num2+2);
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    ll sum = 0;
    rep(i,n-1){
        sum += a[i];
        if(sum*2 >= a[i+1]) ++ans;
        else ans = 0;
    }
    ++ans;

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


Measured memory_bytes: 3972
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

bool f(vi &x, int need) {
    set<int> nex, cur;
    cur.insert(0);
    each(a, x) {
        nex.clear();
        each(b, cur) {
            nex.insert(b + a);
            nex.insert(b - a);
        }
        swap(cur, nex);
    }
    return !!cur.count(need);
}

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

    string S;
    int X, Y;
    while (cin >> S >> X >> Y) {
        int p = 0, q = 0;
        S += 'T';

        vi xx, yy;
        bool first = true;
        each(a, S) {
            if (a == 'T') {
                if (first)X -= q, first = false;
                else if (q > 0) (p ? yy : xx).push_back(q);
                q = 0;
                p = 1 - p;
            } else {
                q++;
            }
        }
        string ans = "No";
        if (f(xx, X) && f(yy, Y))ans = "Yes";
        cout << ans << endl;
    }
}

Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1e6+7;
int n;
long long Max[10];
long long Min[10];
int main() {
  cin >> n;
  for (int i = 0; i < 10; i++)
    Max[i] = -1e15, Min[i] = 1e15;
  long long x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    Max[0] = max(Max[0], x + y);
    Max[1] = max(Max[1], -x + y);
    Max[2] = max(Max[2], x - y);
    Max[3] = max(Max[3], -x - y);
    Min[0] = min(Min[0], x + y);
    Min[1] = min(Min[1], -x + y);
    Min[2] = min(Min[2], x - y);
    Min[3] = min(Min[3], -x - y);
  }
  long long ans = 0;
  for (int i = 0; i < 4; i++) ans = max(Max[i] - Min[i], ans);
  cout << ans << endl;
}

Measured memory_bytes: 3548
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i, n) cin >> L[i];
    sort(all(L));
    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        for(int j = i+1; j < n; j++) {
            int a = L[i];
            int b = L[j];
            int r = lower_bound(all(L), a+b) - L.begin();
            int l = max(i, j) + 1;
            ans += max(0, r - l);
        }
    }

    cout << ans << endl;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n, a;
    cin >> n >> a;
    ll x[n];
    rep(i, n) { cin >> x[i]; }

    ll size = 50 * n + 1;
    ll dp0[n + 1][size] = {};
    ll dp1[n + 1][size] = {};

    dp0[0][0] = 1;
    dp0[1][x[0]] = 1;

    repd(i, 1, n) {
        if (i % 2 == 0) {
            for (int j = 0; j <= i + 1; j++) {
                rep(s, size) {
                    if (s - x[i] < 0) {
                        dp0[j][s] = dp1[j][s];
                    } else {
                        dp0[j][s] = dp1[j][s] + dp1[j - 1][s - x[i]];
                    }
                }
            }
        } else {
            for (int j = 0; j <= i + 1; j++) {
                rep(s, size) {
                    if (s - x[i] < 0) {
                        dp1[j][s] = dp0[j][s];
                    } else {
                        dp1[j][s] = dp0[j][s] + dp0[j - 1][s - x[i]];
                    }
                }
            }
        }
    }

    ll ans = 0;
    if (n % 2 == 0) {
        repd(i, 1, n + 1) { ans += dp1[i][a * i]; }
    } else {
        repd(i, 1, n + 1) { ans += dp0[i][a * i]; }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5564
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int[] A = sc.IntArray();
        int[] B = sc.IntArray();
        int[] C = sc.IntArray();

        int last = -1;
        
        int ans = 0;

        for (int i = 0; i < N; i++)
        {
            int a = A[i] -1;
            ans += B[a];
            if (i + 1 < N)
            {
                int next = A[i + 1] - 1;
                if (a + 1 == next)
                {
                    ans += C[a];
                }
            }

        }
        
        Console.WriteLine(ans);
        
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

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

inline void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
string s;

// x := 1 ... in '(', := 0 ... ok
// p is current position.
void f (int p, int x) {  
  if (p == int(s.size()) - 1) {
    if (x == 0) {
      if (s[p] == '(') {
        s += ")";
        return;
      }
      s = "(" + s;
      return;
    }
    else if (x == 1 && s[p] == ')') {
      return;
    }
    else if (x == 1 && s[p] == '(') {
      s += "))";
      return;
    }
    else {
      if (s[p] == '(') {
        rep(i,x+1) s += ")";
        return;
      }
      else {
        rep(i,x-1) s += ")";
        return;
      }
    }
  }
  else if (x == 0 && s[p] == '(') {
    f(p + 1, x + 1);
    return;
  }
  else if (x == 0 && s[p] == ')') {
    // error
    s = "(" + s;
    return f(p + 2, 0);
  }
  else if (x != 0 && s[p] == ')') {
    f(p + 1, x-1);
    return;
  }
  else if (x != 0 && s[p] == '(') {
    f(p + 1, x + 1);
    return;
  }
  return;
}

int main(void) {
  init();
  cin >> n >> s;

  f(0, 0);
  cout << s << endl;
  
  return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    string s;
    cin >> s;

    cout << string(s.size(), 'x');
    nl;

    return 0;
}




Measured memory_bytes: 3604
n,*a=`dd`.split.map &:to_i
f=0
loop{
	b=a.map{|e|e&1^1}
	s=b.reduce :+
	if s==n&&a[0]-=1
	elsif s==n-1&&(0...n).find{|i|b[i]==0&&a[i]>1&&a[i]-=1}
	else
		f^=s&1
		break
	end
	g=a.reduce(:gcd)
	a=a.map{|e|e/g}
	f^=1
}
puts %w(Second First)[f]

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

map<string, int> cont;

int main(){
	int n;
	cin>>n;
	long long res=0;
	
	for (int i=0; i<n; i++){
		string s;
		cin>>s;
		
		sort(s.begin(), s.end());
		
		res+=cont[s];
		cont[s]++;
		
	}
	
	
	cout<<res<<endl;
}


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

int _MAX(int a,int b)
{
    return a>b?a:b;
}

int _MIN(int a,int b)
{
    return a<b?a:b;
}

int main()
{
    int a,b,c,t,p,o;
    scanf("%d %d %d",&a,&b,&c);
    t=_MAX(a,b);
    t=_MAX(t,c);
    o=_MIN(a,b);
    o=_MIN(o,c);
    if(t==a)
    {
        if(o==b)
            p=c;
        else
            p=b;
    }
    else if(t==b)
    {
        if(o==a)
            p=c;
        else
            p=a;
    }
    else
    {
        if(o==a)
            p=b;
        else
            p=a;
    }
    a=t;
    b=p;
    c=o;
    if((b+c)%2==1)
        a+=2;
    printf("%d\n",(a*2-(b+c))/2);
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, Q;
int A[50], B[50], C[50], D[50];
int num[15], ans = 0;

int Solve(){
  int now = 0;
  for (int i = 0; i < Q; i++){
    if (num[B[i]] - num[A[i]] == C[i]) now += D[i];
  }
  ans = max(ans, now);

  return 0;
}

int Make(int res, int turn){
  if (turn == N){
    Solve();
    return 0;
  }
  for (int i = res; i <= M; i++){
    num[turn + 1] = i;
    Make(i, turn + 1);
  }
  return 0;
}

int main(){
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 0; i < Q; i++){
    scanf("%d%d%d%d", A + i, B + i, C + i, D + i);
  }
  Make(1, 0);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3828
def String_kind(S):
    S_kind,S_kind_num,count = set(),{},0
    OP = []
    for i in range(len(S)):
        if S[i] not in S_kind:
            S_kind.add(S[i])
            S_kind_num[S[i]] = count
            count += 1
        OP.append(S_kind_num[S[i]])

    return OP

def main():
    S = input()
    T = input()

    S_kind,T_kind = String_kind(S),String_kind(T)
    if S_kind == T_kind:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 6832
h, w, k = list(map(int, input().split()))

masu = [input() for _ in range(h)]

ans = 0
for idx_h in range(2 ** h):
    for idx_w in range(2 ** w):
        m = masu.copy()
        for i_row, row in enumerate(m):
            for j_col, col in enumerate(row):
                if idx_h & (2 ** i_row) > 0 or idx_w & (2 ** j_col) > 0:
                    # m[i_row][j_col] = 'r'
                    m[i_row] = m[i_row][:j_col] + 'r' + m[i_row][j_col+1:]
        
        count_black = sum(map(lambda x: x.count('#'), m))
        if count_black == k:
            ans += 1

print(ans)


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

int main(){
	int a, b, c;
	unordered_set<int> s;
	cin >> a >> b >> c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout << s.size();
	return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Main {
	int N,T,size;
    int[] A,segment;

    public void init(int _size){
        size = 1;

        while(size < _size)size *= 2;
        segment = new int[2 * size];
        for(int i = 0;i < 2 * size - 1;i++){
            segment[i] = Integer.MIN_VALUE;
        }
    }

    public void update(int i,int a){
        i += size - 1;
        segment[i] = a;

        while(i > 0){
            i = (i - 1) / 2;
            segment[i] = Math.max(segment[i * 2 + 1], segment[i * 2 + 2]);
        }
    }

    public int query(int a,int b,int k,int l,int r){
        if(r <= a || b <= l)return Integer.MIN_VALUE;

        if(a <= l && r <= b)return segment[k];
        else{
            int vl = query(a,b,k * 2 + 1,l,(l + r) /2);
            int vr = query(a,b,k * 2 + 2,(l + r) / 2,r);

            return Math.max(vl, vr);
        }
    }

    public void solve() {
        N = nextInt();
        T = nextInt();

        init(N);
        A = new int[N];
        for(int i = 0;i < N;i++){
            A[i] = nextInt();
            update(i,A[i]);
        }

        TreeMap<Integer,Integer> treeMap = new TreeMap<Integer,Integer>();

        for(int i = 0;i < N;i++){
        	int max = query(i,size,0,0,size);
        	int diff = max - A[i];
        	treeMap.put(diff, treeMap.containsKey(diff) ? treeMap.get(diff) + 1 : 1);
        }

        int key = treeMap.lastKey();
        out.println(treeMap.get(key));
    }

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 28520
#include <bits/stdc++.h>
#define int long long 

using namespace std;

const int maxn = 3e5 + 7;
vector<int> add[maxn], del[maxn];
int sum1[maxn], sum2[maxn], ans[maxn], n, l[maxn], r[maxn], m;
vector<int> vt[maxn];

int BIT[maxn];

void Update(int pos, int val)
{
    for(; pos < maxn; pos += pos & -pos)
    {
        BIT[pos] += val;
    }
}

int Query(int pos)
{
    int ans = 0;
    for(; pos > 0; pos -= (pos & -pos))
    {
        ans += BIT[pos];
    }
    return ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> l[i] >> r[i];
        add[l[i]].push_back(l[i]);
        del[r[i]].push_back(l[i]);
    }
    for(int i = 1; i <= m; i++)
    {
        for(int j = i; j <= m; j+= i)
        {
            vt[j].push_back(i);
        }
    }
    for(int i = 1; i <= m; i++)
    {
        for(auto j: add[i]) Update(j, 1);
        for(auto j: vt[i])
        {
            ans[j] += Query(i) - Query(i - j);
        }
        for(auto j: del[i]) Update(j, -1);
    }
    for(int i = 1; i <= m; i++) cout << ans[i] << '\n';
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n;
  int ans = 0, num = 1;
  for (int i = 1; i <= n; ++i) {
    int s = 0, t = i;
    while (t % 2 == 0) {
      ++s;
      t /= 2;
    }
    if (s > ans) num = i, ans = s;
  }
  cout << num;

  return 0;
}



Measured memory_bytes: 3624
/*
	author: parv2809
*/

#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

int powmd(int a, int b) {
	if (b == 1)	return a;
	if (b == 0)	return 1;

	int half = powmd(a, b / 2);
	int ans = half * half;
	ans %= mod;
	if (b & 1) {
		ans *= a;
	}
	ans %= mod;
	return ans;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

int mat[16][16];
int dp[(1 << 16)], sums[(1 << 16)];

int calculate(int mask) {
	int ans = 0;
	for (int i = 0; i < 17; i++) {
		if (mask & (1 << i)) {
			for (int j = i + 1; j < 17; j++) {
				if (mask & (1 << j)) {
					ans += mat[i][j];
				}
			}
		}
	}
	return ans;
}

void pre_compute_sums() {
	for (int i = 0; i <= (1 << 16); i++) {
		sums[i] = calculate(i);
		dp[i] = inf;
	}
}

int solve(int mask) {
	if (mask == 0)
		return 0;
	if (dp[mask] != inf)
		return dp[mask];

	int s = mask;
	int ans = 0;

	while (s > 0) {
		ans = max(ans, sums[s] + solve(mask - s));
		s = (s - 1)&mask;
	}

	return dp[mask] = ans;
}

int32_t main() {

	fastIO();
	int t = 1;
	w(t) {
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> mat[i][j];
			}
		}
		pre_compute_sums();
		cout << solve((1 << n) - 1);
		nl;
	}

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Measured memory_bytes: 4660
#include <bits/stdc++.h>
#include<functional>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
int main()
{
  int N, X;
  cin >> N  >> X;
  vector<int > L(N);
  vector<int > D(N + 1);
  D[0] = 0;
  REP(i, N) {
    cin >> L[i];
    D[i + 1] = D[i] + L[i];
  }
  int count = 0;
  REP(i, N + 1){
    if(D[i] <= X){
      count ++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $c = [];
  $s = [];
  $f = [];
  for ($i=0; $i<$n-1; $i++) {
    list($c[], $s[], $f[]) = explode(" ", trim(fgets(STDIN)));
  }

  for ($i=0; $i<$n-1; $i++) {
    $ans = $s[$i];
    $ans += $c[$i];
    for ($j=$i+1; $j<$n-1; $j++) {
//      echo $i." ".$ans.PHP_EOL;
      if($ans <= $s[$j]){
        $ans = $s[$j];
        $ans += $c[$j];
      }else{
        $cnt = intdiv($ans-$s[$j]+$f[$j]-1, $f[$j]);
        $ans = $s[$j] + $f[$j]*$cnt;
        $ans += $c[$j];
      }
    }
    echo $ans.PHP_EOL;
  }
  echo "0";

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

long long arr[200005];
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n,f;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	f = arr[0];
	long long suma = 0, sumb = 0;
	for(int i=1;i<n;i++){
		if(arr[i] < f){
			suma += f - arr[i];
		}else if(arr[i] > f){
			f = arr[i];
		}
	}
	cout<<suma<<endl;
	return 0;
}

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

int n;
vector<int> v;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int q, y; cin >> q;
        if (q != 2) cin >> y;
        
        if (q == 0) v.push_back(y);
        else if (q == 1) cout << v[y] << endl;
        else v.pop_back();
    }
    
    return 0;
}


Measured memory_bytes: 3816
n = int(input())
items = []
for i in range(n):
  s, p = input().split()
  p = int(p)
  items.append((s, p, i+1))

from operator import itemgetter
sorted_items = sorted(items, key=itemgetter(1), reverse=True)
sorted_items = sorted(sorted_items, key=itemgetter(0), reverse=False)

for key, value, ind in sorted_items:
  print(ind)




Measured memory_bytes: 3060
H,W = map(int,input().split())
grid = [input() for i in range(H)]

dp = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    if grid[i][0] == '#':
        break
    dp[i][0] = 1

for j in range(W):
    if grid[0][j] == '#':
        break
    dp[0][j] = 1

for i in range(1,H):
    for j in range(1,W):
        if grid[i][j] == '.':
            dp[i][j] = dp[i-1][j]+dp[i][j-1]
            dp[i][j] %= 1000000007

print(dp[H-1][W-1]%1000000007)

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

string s;
vector<char> vec;

int main() {
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == 'S') {
			vec.pb(s[i]);
		} else {
			if (vec.size() > 0 && vec.back() == 'S') {
				vec.pop_back();
			} else {
				vec.pb(s[i]);
			}
		}
	}
	cout << vec.size() << endl;
	return 0;
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  int ans=0;
  cin >> n >> k;
  int x;
  for(int i=0;i<n;i++){
    cin >> x;
    if(x*2>(k-x)*2)ans+=(k-x)*2;
    else ans+=x*2;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1 && b==1)
    {
        cout<<"Draw"<<endl;
        return 0;
    }
    if(a==1)
        cout<<"Alice"<<endl;
    else if(b==1)
        cout<<"Bob"<<endl;
    else if(a > b)
        cout<<"Alice"<<endl;
    else if(a < b)
        cout<<"Bob"<<endl;
    else
        cout<<"Draw"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, K;
int x[100], y[100];

bool check(int top, int bottom, int right, int left) {
  int cnt = 0;
  rep(k, 0, N) {
    int cx = x[k];
    int cy = y[k];
    if (left <= cx && cx <= right && bottom <= cy && cy <= top) {
      ++cnt;
    }
  }

  return cnt >= K;
}

int dummy[1000000];

int main() {
  cin >> N >> K;
  rep(i, 0, N) { cin >> x[i] >> y[i]; }

  ll ans = numeric_limits<ll>::max();
  rep(i, 0, N) {
    rep(j, 0, N) {
      rep(k, 0, N) {
        rep(l, 0, N) {
          ll top = max(y[i], max(y[j], max(y[k], y[l])));
          ll bottom = min(y[i], min(y[j], min(y[k], y[l])));
          ll left = min(x[i], min(x[j], min(x[k], x[l])));
          ll right = max(x[i], max(x[j], max(x[k], x[l])));

          if (check(top, bottom, right, left)) {
            chmin(ans, (top - bottom) * (right - left));
          }
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3656
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

X=lines[0][0]
N=lines[0][1]

unless N==0
  line=lines[1]
  (N+1).times do |k|
  unless line.include? (X-k)
    p X-k
    break
  end
  unless line.include? (X+k)
    p X+k
    break
  end
end
else print X
end


Measured memory_bytes: 14380
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll n,m;
bool keta(ll nn){
  ll ret = 0;
  while(nn>0){nn/=10;ret++;}
  return n == max(1LL,ret);
}
string tos(ll i){
  string ret ="";
  while(i > 0){
    ret = ret+((char)('0'+i%10));
    i/=10;
  }
  if(ret == "")ret = "0";
  reverse(ALL(ret));
  return  ret;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  bool hoge  = false;
  vector<pair<ll,ll>>pll(m);
  for(int i=0;i<m;i++){
    cin>>pll[i].F>>pll[i].S;
    if(pll[i].F == 1 && n!=1 && pll[i].S == 0)hoge=true;
  }
  if(hoge){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=0;i<1000;i++){
    if(keta(i) == false)continue;
    bool fl = true;
    string s = tos(i);
    //cout<<s<<endl;
    for(int j=0;j<m;j++){
      if(s[pll[j].F-1]-'0' != pll[j].S){
	fl = false;
      }
    }
    if(fl){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            string result = s.Substring(0,3);

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25884
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


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


A, B, N = inpl()


def calc(x):
    return (A * x // B) - A * (x // B)


ans = -1

for a in range(1, A + 5):
    x = B * a - 1
    if x > N:
        break
    tmp = calc(x)
    ans = max(ans, tmp)


if ans == -1:
    if N <= A:
        for x in range(N + 1):
            ans = max(ans, calc(x))
    else:
        ans = calc(N)

print(ans)


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

int main() {
	int a, b, c, d;
	cin >> a >> b>>c>>d;
	if((a+b)>(c+d)){
	cout << "Left"<< endl;
  }
	else if((a+b)==(c+d)){
		cout << "Balanced" << endl;
	}
	else{
		cout << "Right" << endl;
	}
}

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


typedef pair<int, int> pii;

char field[51][51];
int dist[51][51];

const int INF = 1 << 29;
int h, w;

int main() {
    ios::sync_with_stdio(false);
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            cin >> field[i][j];
            dist[i][j] = INF;
        }
    queue<pii> q;
    q.push(pii(0,0));
    dist[0][0] = 0;
    while (q.size()) {
        pii p = q.front();
        q.pop();
        int cx = p.second;//col
        int cy = p.first;//row
        int ccost = dist[cy][cx];
        const int dy[] = {-1, 0, 0, 1};
        const int dx[] = {0, -1, 1, 0};
        
        for (int k = 0; k < 4; k++) {
            int ny = cy + dy[k];
            int nx = cx + dx[k];
            if (ny >=0 && nx >= 0 && ny < h & nx < w && dist[ny][nx] == INF && field[ny][nx] == '.') {
                dist[ny][nx] = ccost + 1;
                q.push(pii(ny, nx));
            }
        }
    }
    if (dist[h-1][w-1] == INF)
        cout << -1 << endl;
    else {
        int a = dist[h-1][w-1]+1;
        int b = 0;
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (field[i][j] == '.') {//if white
                    b++;
                }
        
        cout << b - a << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[10];
int n;
int main(void) {
    scanf("%d", &n);
    puts("0");
    fflush(stdout);
    scanf("%s", s);
    bool flag1, flag2;
    if(s[0] ==  'V') return 0;
    if(s[0] == 'M') flag1 = 1;
    else flag1 = 0;
    int l = 0, r = n;
    while(l < r) {
        int m = (l + r) >> 1;
        printf("%d\n", m);
        fflush(stdout);
        scanf("%s", s);
        if(s[0] == 'V') return 0;
        if(s[0] == 'M') flag2 = 1;
        else flag2 = 0;
        int t = m - l - 1;
        if(t & 1) {
            if(flag1 == flag2) l = m;
            else r = m;
        } else {
            if(flag1 == flag2) r = m;
            else l = m, flag1 = flag2;
        }
    }
    fflush(stdout);
}

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

int main()
{
	int a, b;
	while (cin >> a >> b, !(a == 0 && b == 0)) {
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				if ((i + j) % 2 == 0) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
let id x = x

let () =
    let ss = Scanf.sscanf(read_line()) "%d" id in
    let rec f t r n = if r >= t then f t (r - t) (n + 1) else (n, r) in
    let (hh, ss')  = f 3600 ss  0  in
    let (mm, ss'') = f 60   ss' 0 in
    Printf.printf "%d:%d:%d\n" hh mm ss''


Measured memory_bytes: 2392
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int N;
string S;
map<pair<int, int>, int> mp;

bool is(int s, int t) {
	if (s == t) return true;
	if (t - s < 3 || S[s] != 'm' || S[t - 1] != 'w') return false;

	P p(s, t);
	int r = mp[p];
	if (r) return r == 1 ? true : false;

	for (int i = s + 1; i < t - 1; i++) {
		if (S[i] == 'e' && is(s + 1, i) && is(i + 1, t - 1)) {
			mp[p] = 1;
			return true;
		}
	}
	mp[p] = -1;
	return false;
}

int main()
{
	cin >> S;
	N = S.size();
	cout << (is(0, N) ? "Cat" : "Rabbit") << endl;
	return 0;
}

Measured memory_bytes: 3948
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final int N = sc.nextInt();
		final String S = sc.next();

		int cnt = 0;
		int index = 0;
		while((index = S.indexOf("ABC", index))!=-1) {
			cnt++;
			index++;
		}
		out.println(cnt);
	}
}


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

using namespace std;

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

    long long n, w;
    cin>>n>>w;
    vector<long long> weight(n), value(n);
    for(int i=0;i<n;i++){
        cin>>weight[i]>>value[i];
    }

    int maxValue=1e5+1;
    vector< vector<long long> > dp(2, vector<long long>(maxValue));

    for(int i=1;i<maxValue;i++){
        dp[0][i]=INT_MAX;
    }

    for(int i=1;i<n+1;i++){
        int current=i%2;
        int last=!current;
        for(int j=0;j<maxValue;j++){
            // building dp[i][j]
            dp[current][j]=dp[last][j];

            if((j-value[i-1])>=0){
                dp[current][j]=min(dp[current][j], dp[last][j-value[i-1]]+weight[i-1]);
            }
        }
    }

    long long ans=INT_MIN;

    int index=(n%2);
    for(int i=0;i<maxValue;i++){
        if(dp[index][i]<=w)
            ans=max((long long)i, ans);
    }
    cout<<ans<<endl;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n,x; cin>>n>>x;
  vector<int> l(n, 0);
  vector<int> d(n+1, 0);
  int ans = 1;
  rep(i,n) {
    int l; cin>>l;
    d[i+1] = d[i]+l;
    if (d[i+1]<=x) ans++;
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int rept=0; rept<n; rept++){
			int x = in.nextInt(), y = in.nextInt();
			int dp[][] = new int[x+1][y+1];
			HashSet<Integer> obs = new HashSet<Integer>();
			int m = in.nextInt();
			for(int l=0; l<m; l++){
				int x1 = in.nextInt(), y1 = in.nextInt(), x2 = in.nextInt(), y2 = in.nextInt();
				obs.add(new Integer(sub(x1,y1,x2,y2)));
				obs.add(new Integer(sub(x2,y2,x1,y1)));
			}
			dp[0][0] = 1;
			for(int i=1; i<=x; i++){
				if(!obs.contains(new Integer(sub(i-1,0,i,0)))){
					dp[i][0] += dp[i-1][0];
				}
			}
			for(int j=1; j<=y; j++){
				if(!obs.contains(new Integer(sub(0,j-1,0,j)))){
					dp[0][j] += dp[0][j-1];
				}
			}
			for(int i=1; i<=x; i++){
				for(int j=1; j<=y; j++){
					if(!obs.contains(new Integer(sub(i-1,j,i,j)))){
						dp[i][j] += dp[i-1][j];
					}
					if(!obs.contains(new Integer(sub(i,j-1,i,j)))){
						dp[i][j] += dp[i][j-1];
					}
				}
			}
			if(dp[x][y]==0) System.out.println("Miserable Hokusai!");
			else System.out.println(dp[x][y]);
		}
	}
	
	private static int sub(int x1, int y1, int x2, int y2){
		return x1*(1<<20) + y1*(1<<15) + x2*(1<<10) + y2*(1<<5);
	}
	
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N, NG1, NG2, NG3;
int main()
{
    int N;
    cin >> N;
    map<int,int> mp;
    int no;
    REP( i, N )
    {
        cin >> no;
        mp[ no ]++;
    }
    int count{};
    for( auto &x : mp )
    {
        if( x.second % 2 != 0 ) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
#define endl '\n'
//char a[2000][2000];
using namespace std;
ll countDivisibles(ll A, ll B, ll M) 
{ 
    // Add 1 explicitly as A is divisible by M 
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
} 
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);   
    //cin>>tests;
  while(tests--)
    { 
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
       // cout<<countDivisibles(a,b,c*d/__gcd(c,d));
        cout<<(b-a+1)-countDivisibles(a,b,c)-countDivisibles(a,b,d)+countDivisibles(a,b,c*d/(__gcd(c,d)));
    }
}


Measured memory_bytes: 256
#include<iostream>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
using namespace std;

int main() {
    int n;
    cin >> n;
    int A[n][n];
    bool isNecessary[n][n];
    rep(i, n) rep(j, n) {
        cin >> A[i][j];
        isNecessary[i][j] = true;
    }
    rep(k, n) rep(i, n) rep(j, n) {
        if (A[i][j] > A[i][k] + A[k][j]) {
            printf("-1\n");
            return 0;
        }
        if (A[i][j] == A[i][k] + A[k][j] && A[i][k] && A[k][j]) {
            isNecessary[i][j] = false;
        }
    }
    int64_t ans = 0;
    rep(i, n) REP(j, i+1, n) {
        if (isNecessary[i][j]) ans += A[i][j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 640