akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
//#include <utility>

using namespace std;
const long nPrime = 1000000007;

void LF_Prime_Sequence(const long &n, vector<long> &viPrime){
    if(n < 2){
        return;
    }
    viPrime.clear();
    vector<char> aiType(n + 1,0);
    for (long i = 2; i * i <= n; i++){
        for(long j = 2; j * i <= n; j++){
            aiType[j * i] = 1;
        }
    }
    for (long i = 2; i <= n; i++){
        if(aiType[i] == 0){
            viPrime.push_back(i);
        }
    }
    return;
}
void LF_Factorization(long n, vector<pair<long, long>> &viiFactor){
    if(n < 2){
        return;
    }
    vector<long> viPrime;
    LF_Prime_Sequence(sqrt(n)+1, viPrime);

    for(long i = 0; i < viPrime.size(); i++){
        long nCount = 0;
        while(n % viPrime[i] == 0){
            n /= viPrime[i];
            nCount++;
        }
        if(nCount > 0){
            viiFactor.push_back(make_pair(viPrime[i], nCount));
        }
    }
    if(n > 1){
        viiFactor.push_back(make_pair(n, 1));
    }
    return;
}

//階乗
long Factorial(const long &n){
    //nPrime = 1000000007
    long nReturn = 1;
    for(long i = 2; i <= n; i++){
        nReturn *= i;
        nReturn %= nPrime;
    }
    return nReturn;
}

//素数の逆元
long Inverse(const long &n){
    //nPrime = 1000000007
    if (n % nPrime == 0){
        return 0;
    }
    long a = n, b = nPrime, u = 1, v = 0;
    while (b > 0) {
        long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= nPrime;
    if (u < 0){
        u += nPrime;
    }
    return u;    
}

int main(){
    long n, m;
    scanf("%ld %ld", &n, &m);
    if(n == 1){
        printf("1");
        return 0;
    }
    vector<pair<long, long>> viiFactor;
    LF_Factorization(m,viiFactor);
    
    long nAns = 1;
    for(long i = 0; i < viiFactor.size(); i++){//高々32個
        long k = viiFactor[i].second;
        long nChoose = Factorial(n-1) * Factorial(k);
        nChoose %= nPrime;
        nChoose = Factorial(n - 1 + k) * Inverse(nChoose);
        nChoose %= nPrime;
        nAns *= nChoose;
        nAns %= nPrime;
    }
    
    if(nAns < 0){
        nAns += nPrime;
    }

    printf("%ld", nAns);
    return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
/*
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
*/
int W,H;
int C[50][50];
void DFS(int x,int y){
	C[x][y]=0;
	FOR(i,-1,2){
		FOR(j,-1,2){
			if(0<=x+i&&x+i<H&&0<=y+j&&y+j<W&&C[x+i][y+j]==1){
				DFS(x+i,y+j);
			}
		}
	}
}
int main(){
	while(1){
		cin>>W>>H;
		if(W==0&&H==0){
			break;
		}
		//
		FOR(i,0,H){
			FOR(j,0,W){
				cin>>C[i][j];
			}
		}
		int ans=0;
		FOR(i,0,H){
			FOR(j,0,W){
				if(C[i][j]==1){
					DFS(i,j);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3180
#include <algorithm>
#include<bits/stdc++.h>
#include <ios>
#include <iterator>
using namespace std;
#define ll long long 
#define f(n)  for(ll int i=0;i<n;i++) 
#define pb push_back
#define mp make_pair
#define vi vector<ll int>
#define all(v)   v.begin(),v.end()  
#define take(n)   ll int n;cin>>n;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
  int h1,s1,h2,s2;
    cin>>h1>>s1>>h2>>s2;
    int v1 =h1/s2;
    int v2=h2/s1;
    int f=0;
    while(h1>0&&h2>0){
        if(f%2==0){
            h2=h2-s1;
        }
        else{
            h1=h1-s2;
        }
        f++;
    }
    if(h1<=0){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 3636
import sys


class Item:
    def __init__(self, amount, price):
        self.amount = amount
        self.price = price


items = [ Item(200, 380),                   #  380
          Item(300, 550),                   #  550
          Item(500, 850),                   #  850
          Item(200 * 5, 380 * 5 * 0.8),     # 1520
          Item(300 * 4, 550 * 4 * 0.85),    # 1870
          Item(500 * 3, 850 * 3 * 0.88) ]   # 2244


dp = [sys.maxint] * 5001
dp[0] = 0
for item in items:
    for i in xrange(0, 5001):
        if i + item.amount <= 5000:
            dp[i + item.amount] = min(dp[i + item.amount], dp[i] + item.price)

while True:
    amount = int(sys.stdin.readline())
    if amount == 0:
        exit()
    print int(dp[amount])

Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int d,sum;
    sum = 0;
    while (cin >> d) {
        for (int i=1;i<=((600-d)/d);i++) {
            sum = sum + (i*d*i*d*d);
        }
        cout << sum << endl;
        sum = 0;
    }
}



Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

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

int main(){
    string inp;
    cin >> inp;

    // 後ろから考えていくので文字列を全て反転する
    string judge[] = {"eraser", "dreamer", "erase", "dream"};
    reverse(all(inp));
    rep(i, 4) reverse(all(judge[i]));

    bool next = true;
    while(next){
        next = false;
        rep(i, 4){
            auto itr = inp.find(judge[i]);
            if(itr != string::npos && itr == 0){
                inp.erase(itr, judge[i].size());
                next = true;
                break;
            }
        }
    }

    if(inp.size() > 0){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int mod=1e9+7;
const LL maxN=4e18;
LL fib[205];
LL getnum(LL x,LL y,LL X,LL Y){//x<y
    LL ret=0;
    if(x<=X&&y<=Y) ret+=(Y-y+x)/x;
    if(x<=Y&&y<=X) ret+=(X-y+x)/x;
    return ret%mod;
}
void solve(LL X,LL Y){
    if(X>Y) swap(X,Y);
    int k=1;
    while(fib[k+1]<=X&&fib[k+2]<=Y) k++;
    printf("%d ",k);
    if(k==1) {printf("%lld\n",X*Y%mod);return;}
    LL ret=getnum(fib[k],fib[k+1],X,Y);
    for(int i=1;i<k;i++)
        ret+=getnum(fib[i]*fib[k-1-i] +fib[k] ,fib[i]*fib[k-i] +fib[k+1] ,X,Y);
    printf("%lld\n",ret%mod);
}
void pre(){
    fib[0]=fib[1]=1;
    for(int i=1;fib[i]<=maxN;i++) fib[i+1]=fib[i]+fib[i-1];
}

int main(){
    pre();
    int T;
    scanf("%d",&T);
    while(T--){
        LL X,Y;
        scanf("%lld%lld",&X,&Y);
        solve(X,Y);
    }
    return 0;
}

Measured memory_bytes: 3968
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  void run() {
    for (; ; ) {
      int n = ni();
      int p = ni();

      if ( (n | p) == 0 ) break;

      int[] s = new int[ n ];
      int v = p;
      int idx = 0;
      for (; ; ) {
        if ( v > 0 ) {
          ++s[ idx ];
          --v;

          if ( v == 0 ) {
            boolean flag = true;
            for ( int i = 0; i < n; ++i ) {
              if ( i == idx ) continue;
              flag &= s[ i ] == 0;
            }
            if ( flag ) {
              break;
            }
          }
        } else {
          v += s[ idx ];
          s[ idx ] = 0;
        }


        ++idx;
        idx %= n;
      }


      System.out.println(idx);
    }

  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 20304
if __name__ == "__main__":
  n = int(input())
  ai = list(map(int, input().split()))
  li = []
  for i in range(n - 1):
    if ai[i] > ai[i + 1]:
      li.append(ai[i] - ai[i + 1])
      ai[i+1]=ai[i]
    else:
      pass
  print(sum(li))

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

signed main() {
    int ans = 0;
    int N, M;
    cin >> N >> M;

    pair<int, int> all = make_pair(0, N);

    REP(i, M) {
        int L, R;
        cin >> L >> R;

        all.first  = max(all.first , L);
        all.second = min(all.second, R);
    }

    ans = max(0LL, all.second - all.first + 1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
program candy
  implicit none

  integer :: n, i, k
  integer, allocatable :: a(:,:), tot(:)

  read(*,*) n

  allocate(a(n,2))
  read(*,*) a

  allocate(tot(n))

  do i = 1, n
     tot(i) = 0
  end do

  do i = 1, n
     do k = 1, i
        tot(i) = tot(i) + a(k,1)
     end do

     do k = i, n
        tot(i) = tot(i) + a(k,2)
     end do

  end do

  write(*,*) maxval(tot)

end program candy

     

  

  


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

#define ll long long
#define ull unsigned long long 

int main(){
    string s;
    cin >> s;
    int n = s.length();

    --n;
    if(n&1)
        --n;

    for(int i=n; i>=0; --i){
        string a = s.substr(0, i/2);
        string b = s.substr(i/2, a.length());

        if(a==b){
            cout << a.length()*2;
            return 0;
        }
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(I,N) for (int I = 0; I < (N); ++I)
#define fornd(I,N) for (int I = (N) - 1; I >= 0; --I)
#define forab(I,A,B) for (int I = (A); I <= (B); ++I)
#define forabd(I,A,B) for (int I= (B); I >= (A); --I)
#define FOREACH(I,A) for (__typeof__(A)::iterator I=A.begin(); I<A.end(); I++)
#define all(V) (V).begin(), (V).end()
#define pb push_back
#define mp make_pair

typedef long long int ll;

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

const ll mod = 1000000007;

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

  string city;
  int score;
  vector<pair<pair<string, int>, int> > order;
  forn(i, N) {
    cin >> city >> score;
    order.pb(mp(mp(city, -score), i + 1));
  }
  sort(order.begin(), order.end());

  forn(i, N) {
    cout << order[i].second << endl;
  }

  return 0;
}




Measured memory_bytes: 256
#!/usr/bin/env ruby

# Generated by AtcoderGreedy on 2018-06-10
# ABC099 D

# my lib

module Enumerable
  # work just like String#split,
  # except this method does not use regex match
  # but check whether yield succeeds or not.
  def split
    current = nil
    ret = []
    each do |elem|
      if yield elem
        if current
          ret << current
          current = nil
        end
      elsif current
        current << elem
      else
        current = [elem]
      end
    end
    ret << current if current
    ret
  end
end

class Array
  # truncate tail, opposite of drop
  def clip(amount = 1)
    if amount < 0
      raise ArgumentError, "amount == #{amount}, cannot be negative!"
    end
    take_amount = size - amount
    take_amount < 0 ? [] : take(take_amount)
  end
end

def n_choose_k(n, k)
  return 0 unless (0..n).cover? k
  result = 1
  1.upto(k) do |d|
    result *= n
    result /= d
    n -= 1
  end
  result
end

# end of lib

# Your code here

def read_matrix(c)
  ret = []
  c.times do
    ret << gets.chomp.split(' ').map(&:to_i)
  end
  ret
end

N, C = gets.chomp.split(' ').map(&:to_i)
D = read_matrix(C)
c = read_matrix(N)

# $stderr.puts "(N, C) = (#{N}, #{C})"
# $stderr.puts D.inspect
# $stderr.puts c.inspect

groups = Array.new(3) do |_|
  (1..C).map do |color|
    [color, 0]
  end.to_h
end

# $stderr.puts groups.inspect

N.times do |i|
  N.times do |j|
    color = c[i][j]
    groups[(i+j)%3][color] += 1
  end
end

colors_cands = (1..C).to_a.permutation(3)

diffs = colors_cands.map do |colors|
  total = 0
  (0...3).each do |i|
    to_color = colors[i]
    (1..C).each do |from_color|
      # $stderr.puts "from: #{from_color}, to: #{to_color}"
      total +=
        groups[i][from_color] * D[from_color - 1][to_color - 1]
    end
  end
  total
end

puts diffs.min


Measured memory_bytes: 4732
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-25 15:20:24
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=510;
const i64 inf=1ll<<50;
i64 n,a[N][N],f[N][N],ans,s[N][N],S[N][N];
int main()
{
	n=read(); ans=inf;
	fr(i,1,n) fr(j,1,n) if(i!=j) a[i][j]=read();
	fr(i,1,n) fr(j,1,n)
	{
		s[i][j]=s[i-1][j]+s[i][j-1]+a[i][j]-s[i-1][j-1];
		S[i][j]=S[i-1][j]+S[i][j-1]+(i>=j?0:a[i][j])-S[i-1][j-1];
	}
	fr(i,0,n+1) fr(j,0,n+1) f[i][j]=inf;
	f[0][0]=0;
	fr(j,0,n) fr(i,0,j) if(f[i][j]!=inf)
		fr(k,j+1,n+1)
		{
			i64 F=f[i][j];
			F+=S[k?k-1:0][k?k-1:0]-S[k?k-1:0][j?j-1:0]-S[j?j-1:0][k?k-1:0]+S[j?j-1:0][j?j-1:0];
			//fr(I,1,n) if(I>=j&&I<k) fr(J,1,n) if(J>=j&&J<k&&I<J) F+=a[I][J];
			F+=s[n][j?j-1:0]-s[n][i?i-1:0]-s[k?k-1:0][j?j-1:0]+s[k?k-1:0][i?i-1:0];
			//fr(I,1,n) if(I>=i&&I<j) fr(J,1,n) if(J>=k) F+=a[J][I];
			f[j][k]=std::min(f[j][k],F);
		}
		/*
		(-)	000001111222223333
		         i   j    k
		*/
	fr(i,0,n) ans=std::min(ans,f[i][n+1]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<cmath>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a, b, x;

int main() {
	cout << fixed << setprecision(10);
	cin >> a >> b >> x;
	if (a * a * b < 2 * x) {
		cout << (lldo)90 - atan((lldo)a / ((lldo)2 * b - (lldo)2 * x / a / a)) * 180 / 3.141592653589793238462643383279 << endl;
	}
	else {
		cout << (lldo)90 - atan((lldo)2 * x / a / b / b) * 180 / 3.141592653589793238462643383279 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n, m;
  cin >> n >> m;
  string s, t;
  cin>>s>>t;
  bool OK = true;
  ll a = gcd(n, m);
  ll l = a * n / a * m / a;
  ll x = l / n, y = l / m;
  rep(i, n){
    if(i*x/y>sz(t)){
      break;
    }
    if((i*x)%y==0&&s[i]!=t[i*x/y]){
      OK = false;
    }
  }
  cout << (OK ? l : -1) << endl;
}

Measured memory_bytes: 3764
def make_divisors(n):
    if n==1:
        divisors=[1]
        return divisors
    else:
        divisors=[]
        for i in range(1,n):
            if i*i>n:
                break
            if n%i==0:
                divisors.append(i)
                if i!=n//i:
                    divisors.append(n//i)

        divisors.sort()
        return divisors

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())

    d=make_divisors(M)
    for i in range(len(d)):
        if d[i]-N>=0:
            print(M//d[i])
            break

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
10=10
11=5.5
12=4
13=3.25
14=2.8
15=2.5
19=1.9←これ
20=10
21=7
28=2.8
29=2.63
30=10
39/12=3.25
99=5.5
100=100
109=10.9
119=10.82
199=10.47
899=34.58
999=37
1009=100.9
1999=57.84

i:999 z:37.00<<
i:1099.00 z:57.84 <<
i:1199.00 z:59.95 <<
i:1299.00 z:61.86 <<
i:1399.00 z:63.59 <<
i:1499.00 z:65.17 <<
i:1599.00 z:66.62 <<
i:1699.00 z:67.96 <<
i:1799.00 z:69.19 <<
i:1899.00 z:70.33 <<
i:1999.00 z:71.39 <<
i:2099.00 z:104.95
i:2199.00 z:104.71
i:2299.00 z:104.50
i:2399.00 z:104.30
i:2499.00 z:104.12
i:2599.00 z:103.96
i:2699.00 z:103.81
i:2799.00 z:103.67
i:2899.00 z:103.54
i:2999.00 z:103.41 <<
i:3099.00 z:147.57
i:3199.00 z:145.41
i:3299.00 z:143.43
i:3399.00 z:141.62
i:3499.00 z:139.96
i:3599.00 z:138.42
i:3699.00 z:137.00
i:3799.00 z:135.68
i:3899.00 z:134.45
i:3999.00 z:133.30 <<
i:4099.00 z:186.32

1...9
19 29...99
199 299...999
1999 2999...9999
候補の数全部配列にいれて、探索？
桁あたり１０個。１５０個
1-9
19-99

１ずつ足す、１０ずつ足す、１００ずつ足す･･･を10^15まで繰り返すだけでいいか
1->9 1*8
     +1
10->19 1*9
19->99 10*8
       +1
100->109 1*9
109->199 10*9
199->999 100*8
         +1
1000->1009 1*9
1009->1099

微妙･･･

long doubleで小数比較とか
出したあと戻るひつようがあるから、配列に格納するべきか

n/Sn < m/Sm
n*Sm < n*Sn
整数判断できるじゃん
最初に気づかないとだめなやつ

うーん、
+1
+10
+100
+1000の操作だけが解答足るぽい？なんでかはわからん
ああ、２手次で判断するのかな
*/

ll dsum(ll v){
  ll s=0;
  while(v>0){
    s+=v%10;
    v/=10;
  }
  return s;
}

int main(){
  ll K,n=1,d=1; cin>>K;
  while(K--){
    ll nn=n+d;
    ll m=nn+d;
    if(nn*dsum(m)>m*dsum(nn))d*=10;
    cout<<n<<endl;
    n+=d;
  }
}

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

using namespace std;
int main()
{




    long long ai,t,n,a,A,sum=0,b,B,c=0,k,e,f,g;



    cin >> a ;

    while( a != 0)
    {
        b=a%10;

        if(b == 7)
        {
            cout << "Yes";
            return 0;
        }

        a=a/10;


    }
    cout << "No";






return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <queue>
#include <map>
using namespace std;
// 状態を表すクラス pair の場合、typedef しておくと便利
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0;i < (n);i++)
// 10^8 は 1e+8 と書くこともできます
const int INF = 1e+8;
// 迷路を表す文字列の配列
string maze[101];
// w:幅, h:高さ, sx,sy:スタートの座標, gx,gy:ゴールの座標
int w, h, sx, sy, gx, gy;
// d[y][x] := (sx,sy) から (x,y) までの最短距離
int d[101][101];
// 4 近傍
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int bfs(){
  queue<P> que;
  // すべての点を INF で初期化
 for(int y=0 ; y < h ; y++ )
   for(int x=0 ; x < w ; x++ )
     d[y][x] = INF;
 // スターと地点をキューに入れて、その点の距離を 0 にする
 que.push( P(sx,sy) );
 d[sy][sx] = 0;
 while( !que.empty() ){ // キューが空でない間ループ
   // キューから取り出す
   P p = que.front();
   que.pop();
   int x = p.first;
   int y = p.second;
   // 取り出した状態がゴールなら探索を止める
   if( x == gx && y == gy ) break;
   // 移動方向 4 方向をループ
   for(int i=0 ; i < 4 ; i++ ){
     // 移動した後の点を (mx,my) とする
     int mx = x + dx[i];
     int my = y + dy[i];
     // 範囲外に出たときは次の処理へ
     if( mx < 0 || my < 0 || mx >= w || my >= h ) continue;
     // 移動可能でまだ訪れたことがなければキューに入れる
     if( maze[my][mx] !='#' && d[my][mx] == INF ){
       que.push( P(mx,my) );
       d[my][mx] = d[y][x] + 1;
     }
   }
 }
 return d[gy][gx];
}
int main(){
  cin >> h >> w;
  for(int y=0 ; y < h ; y++ ){
    cin >> maze[y];
  }
  /*
  for(int y=0 ; y < h ; y++ ){
    for(int x=0 ; x < w ; x++ ){
      if( maze[y][x] == ’S’ ){
	sx = x;
	
	sy = y;
      }else if( maze[y][x] == ’G’ ){
	gx = x;
	gy = y;
      }
    }
  }
  */
  sx = 0;
  sy = 0;
  gx = w-1;
  gy = h-1;
  int ans = bfs();
  int num = 0;
  if(ans == INF)
    cout << -1 << endl;
  
  else{
    REP(i,h){
      REP(j,w){
	if(maze[i][j] == '#')
	  num++;
      }
    }
    cout << w*h-num-ans-1 << endl;
  }
  //cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        if ( N % 2 == 0) {
            String s1 = S.substring(0, N/2);
            String s2 = S.substring(N/2, N);
            if (s1.equals(s2)) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
#define pb push_back
#define gc getchar
using namespace std;
//const int N=2e5+10;
typedef long long ll;
typedef double db;

int q,a,b,c,d; 

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

int main(){
	int i,j,x,y,l,r,pos,ca,cb,mid;
    for(rd(q);q;--q){
    	rd(a);rd(b);rd(c);rd(d);
    	x=(max(a,b)-1)/(min(a,b)+1)+1;
    	l=0;r=a+b;pos=a+b+1;
    	for(;l<=r;){
    		mid=(l+r>>1);
    		cb=mid/(x+1);ca=mid-cb;
			if(b-cb>(ll)(a-ca)*x) r=(pos=mid)-1;
			else l=mid+1; 
		}
		for(i=c;i<=min(pos,d);++i) putchar((i%(x+1))?'A':'B');
		for(i=max(c,pos+1);i<=d;++i) putchar(((a+b-i+1)%(x+1))?'B':'A');
		putchar('\n');
	}
	return 0;
}
/*
1
4 7 1 11
*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
ll f(ll x){
    if(x==1) return 1;
    else{
        ll res = 1 + (2 * f(x/2));
        return res;
    }
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n; cin>>n; cout<<f(n)<<newl;
}


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

using namespace std;

int main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
	
    string a, b;
    
    cin >> a;
    
    int len = a.size(), ind = 0;
    for(int i = 0; i < len; i++){
    	if(a[i] != 'B'){
    		b.push_back(a[i]);
		}
		else if(b.size()){
			b.pop_back();
		}
	}
	
	cout << b << endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010

ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    ll n,all=0,ans=INF,count=0;
    cin >> n;
    ll x[n];
    for (ll i=0;i<n;i++){
        cin >> x[i];
        all+=x[i];
    }
    count=x[0];
    for (ll i=1;i<n;i++){
        ans=min(abs((all-count)-count),ans);
        count+=x[i];
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int S[10000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>S[i];
    }
    int c=0;
    int q, t;
    cin>>q;
    for(int i=0; i<q; i++) {
        cin>>t;
        for(int j=0; j<n; j++) {
            if(S[j]==t) {
                c++;
                break;
            }
        }
    }
    cout<<c<<'\n';
    return 0;
}

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

  long long A,x,y;
int main()
{
  cin>>A>>x;
  y=A-x;
  if (x>y) swap(x,y);
  while (x)
    {
      A+=y/x*2*x;
      y%=x;
      swap(x,y);
    }
  cout<<A-y;
  exit(0);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        long n = long.Parse(ReadLine());
        string[] s = ReadLine().Split(' ');
        int[] a = new int[n];

        long ans = 0;
        long sum = 0;
        long xor = 0;
        int r = 0;

        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(s[i]);
        }

        for (int l = 0; l < n; l++)
        {
            while (r < n && ((sum + a[r]) == (xor ^ a[r])))
            {
                sum += a[r];
                xor ^= a[r];
                r++;
            }
            ans += r - l;
            sum -= a[l];
            xor ^= a[l];
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 32348
#include<stdio.h>
 
int main(void){
  int i;
  int n;
  int m;
  int a[10010];
  scanf("%d%d",&n, &m);
  for(i = 0; i < m; i++){
    scanf("%d", &a[i]);
    n -= a[i];
  }
  if (n < -1)
    n=-1;
  printf("%d",n);
}

Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define F first
#define s second
#define int long long		
int a[214514];
int b[214514];
signed main(){
	int c,d;
	cin>>c>>d;
	rep(d-c+1,i,d+c)cout<<i<<" ";
	cout<<endl;
}	

Measured memory_bytes: 256
n = int(input())
dish = list(map(int, input().split()))
koyo = list(map(int, input().split()))
tsuika = list(map(int, input().split()))

ans = 0
bdish = -1

for i in dish:
  ans += koyo[i-1]
  if bdish+1 == i:
    ans += tsuika[bdish-1]
  bdish = i
print(ans)

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

template<typename T> vector<T> divisor(T n){
    vector<T> res;
    for (long long i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i * i != n) { res.emplace_back(n/i); }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    long long n;
    cin >> n;
    
    if (n == 2) {
        cout << 1 << '\n';
        return 0;
    }
    
    vector<long long> d = divisor(n), t = divisor(n - 1);
    set<long long> ans;
    
    for (const auto &e : d) if (e != 1) {
        long long val = n;
        while (val % e == 0) val /= e;
        if (val % e == 1) ans.emplace(e);
    }
    for (const auto &e : t) if (e != 1) ans.emplace(e);
    
    cout << ans.size() << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	sort(v.begin(), v.end());
	long long a = 0, b = 0;
	for(int i = n - 1; i >= 0; i--){
		if(i == 0) break;
		if(v[i] == v[i - 1]){
			if(a == 0) a = v[i];
			else if(b == 0)b = v[i];
			else break;
			i--;
		}
	}
 
	cout << a * b <<endl;
 
	return 0;
}

Measured memory_bytes: 3756
n = int(input()); a = []; b = []; x = 0
for i in range(n): A, B = map(int, input().split()); a.append(A); b.append(B)
for i in range(n-1, -1, -1): x += b[i]-(a[i]+x-1)%b[i]-1
print(x)

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

int main()
{
	int N;
	int A[200];

	cin >> N;
	for (int i = 0; i <= 200; i++) cin >> A[i];
	
	int res = 0;

	while (true) {
		bool isOdd = false;

		for (int i = 0; i < N; ++i){
			if (A[i] % 2 != 0) isOdd = true;
		}

		if (isOdd) break;

		for (int i = 0; i < N; ++i) A[i] /= 2;
		
		++res;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N_MAX 100005
#define NIL -1

void print(int t);
int get_depth(int t);

struct node
{
  int parent;
  int left;
  int right;
};

struct node tree[N_MAX];


int get_depth(int t)
{
  int depth=0;
  while(tree[t].parent != NIL){
    t = tree[t].parent;
    depth ++;
  }
  
  return depth;
}


void print(int t)
{
  printf("node %d: ",t);

  printf("parent = %d, ",tree[t].parent);

  printf("depth = %d, ",get_depth(t));

  if(tree[t].parent == NIL){
    printf("root, ");
  }
  else if(tree[t].left == NIL){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }


  int c=tree[t].left;
  printf("[");
  while(c != NIL){
    printf("%d",c);
    c = tree[c].right;
    if(c != NIL){
      printf(", ");
    }
  }
  printf("]\n");
}



int main()
{
  int n, i, j;
  int id, k, c, left=0, r;

  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    tree[i].parent=NIL;
    tree[i].left=NIL;
    tree[i].right=NIL;
  }

  
  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf("%d", &k);
    for(j=0; j<k; j++){
      scanf("%d", &c);
      if(j==0){
	tree[id].left = c;
      }
      else{
	tree[left].right = c;
      }
      left = c;
      tree[c].parent = id;
    }
  }

  
  for(i=0; i<n; i++){
    print(i);
  }
  
  return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>
#include<stdlib.h>
int main(){
  long long a,b,v,w,t;
  scanf("%lld%lld%lld%lld%lld",&a,&v,&b,&w,&t);
  if(abs(b-a)>(v-w)*t)
    puts("NO");
  else
    puts("YES");
  return 0;
}


Measured memory_bytes: 1660
n, m, l = map(int, input().split())

mat_a = []
mat_b = []

for i in range(n):
    array = list(map(int, input().split()))
    mat_a.append(array)
for i in range(m):
    array = list(map(int, input().split()))
    mat_b.append(array)

ans = 0
for i in range(n):
    for k in range(l):
        for j in range(m):
            ans += mat_a[i][j] * mat_b[j][k]
        if k != 0:
            print(' ', end='')
        print('{}' .format(ans), end='')
        ans = 0
    print()


Measured memory_bytes: 6508
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let r: u32 = read();
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    vector<int> a(n),b(m);
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    bool flag = 0;
    for(int i=x+1;i<=y;i++){
        bool fflag = 1;
        rep(j,n){
            if(a[j]>=i)fflag = 0;
        }
        rep(j,m){
            if(b[j]<i)fflag = 0;
        }
        if(fflag)flag = 1;
    }
    if(flag){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
    return 0; 
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

ans = 0

if (a+b) > 2*c:
  if x > y:
    ans += 2*c*y+min(a, 2*c)*(x-y)
  else:
    ans += 2*c*x+min(b, 2*c)*(y-x)
else:
  ans += a*x+b*y
print(ans)

Measured memory_bytes: 38256
#include <stdio.h>

int main(void){
  int a,h,m,s;

  scanf("%d", &a);

  s = a % 60;
  m = a / 60 % 60;
  h = a / 60 / 60 % 24;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

Measured memory_bytes: 1836
from collections import deque
n = int(input())
d = [0]*(n+1)
tree = [[] for _ in range(n+1)]
for i in range(n-1):
  u,v,w = map(int,input().split())
  tree[u].append([v,w])
  tree[v].append([u,w])
q = deque([1])
done = [0]*(n+1)
done[1] = 1
while q:
  now = q.popleft()
  for l in tree[now]:
    if not done[l[0]]:
      q.append(l[0])
      done[l[0]] = 1
      d[l[0]] = d[now] + l[1]
for i in range(1,n+1):
  print(d[i]%2)

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

int main(){
    ll n,d;
    cin >> n >> d;
    vector<ll> x(n);
    vector<ll> y(n);
    rep(i,n) cin >> x[i] >> y[i];
    int count = 0;

    rep(i,n) {
        if(x[i]*x[i] + y[i]*y[i] <= d*d){
            count++;
        }
    }
  
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7;//998244353 ;

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  int x=0;
  rep(i,n)x=(x^a[i]);
  rep(i,n){
    cout << (x^a[i]) << ' ';
  }
  cout << endl;
return 0;}

Measured memory_bytes: 4372
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$N = $sc->nextInt();
$array_num = [];
$result_type = array(
                     'AC' => 0,
                     'WA' => 0,
                     'TLE' => 0,
                     'RE' => 0,
                    );

for($i=0;$i<$N;$i++){
    $s = $sc->next();
    $result_type[$s]++;
}

foreach($result_type as $key=>$value){
    echo $key;
    echo " x ";
    echo $value;
    echo PHP_EOL;
}


Measured memory_bytes: 16072
n = int(input())
a = list(map(int, input().split()))

even_count = 0
ok_count = 0
for ai in a:
  if ai % 2 == 0:
    even_count += 1
    if ai % 3 == 0:
      ok_count += 1
      continue
      
    if ai % 5 == 0:
      ok_count += 1
      continue

if even_count == ok_count:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 38384
import java.util.*;

public class Main{

   public static void main(String[] args){
       Scanner sc =new Scanner(System.in);
       int a,b;
       a=sc.nextInt();
       b=sc.nextInt();
       for(int i=1;i<=3;i++){
           if((a*b*i)%2==1){
               System.out.println("Yes");
               System.exit(0);
           }
       }
       System.out.println("No");
    }
}

Measured memory_bytes: 21972
#include <iostream> 
// #include <stdio.h>
// #include <string>
// #include <cstdlib>
// #include <algorithm>
// #include <string>
using namespace std;
// #define MAX_N 50
// #define MAX_M 50

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if (c <= b && c >= a){
		cout << "Yes";
	} else {
		cout << "No";
	}
    return 0;
 }

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

int main(){
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	if(max(max(a,b),max(max(c,d),e))-min(min(a,b),min(min(c,d),e))>k){
		cout<<":("<<endl;
	}else{
		cout<<"Yay!"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 262144
int main() {
	int n, m;
	cin >> n >> m;
	long long four = (n / 2)*(m / 2);
	long long two = (((n % 2)*m) + ((m % 2)*n))/2;
	map<char, int> wow;
	for (int i = 0;i < n;++i) {
		string s;
		cin >> s;
		for (int q = 0;q < m;++q) {
			wow[s[q]]++;
		}
	}
	for (char i = 'a';i <= 'z';++i) {
		while (four != 0 && wow[i] >= 4) {
			wow[i] -= 4;
			four--;
		}
	}
	if (four != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (char i = 'a';i <= 'z';++i) {
		while (two != 0 && wow[i] >= 2) {
			wow[i] -= 2;
			two--;
		}
	}
	int one = ((n % 2) + (m % 2)) / 2;
	for (char i = 'a';i <= 'z';++i) {
		while (one != 0 && wow[i] >= 1) {
			wow[i]--;
			one--;
		}
		if (wow[i] >= 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    REP(i,s.size()){
        if(s[i]=='+')ans++;
        else ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  rep(i, 4) {
    if (s[i] == '+') ans++;
    else if (s[i] == '-') ans--;
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010
#define PI 3.1415926535
int main(){
	IOS;
	ld a,b,x;cin>>a>>b>>x;
	ld v=a*a*b,ans,y=2.0000;
	if(v<x*y)ans=y*(b/a-(x/(a*a*a)));
	else ans=(b*b*a)/(y*x);
	ans=atan(ans)*180;
	cout<<fixed<<setprecision(10)<<ans/PI;
	
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N),B(M);
    vector<ll> a(N+1,0),b(M+1,0);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    for(int i=1;i<=N;i++){
        a[i] = a[i-1] + A[i-1];
    }
    for(int i=1;i<=M;i++){
        b[i] = b[i-1] + B[i-1];
    }
    ll ans = 0;
    ll j = M;
    for(int i=0;i<= N;i++){
        if(a[i] > K) break;
        while(b[j] > K-a[i]){
            j--;
        }
        ans = max(ans,i+j);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9592
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);
	
	int n;
	public void run() {
		int rect=0,lozenge=0;
		while(sc.hasNext()){
			String str=sc.next();
			String[] sa=str.split(",");
			int[] edge=new int[]{
					Integer.parseInt(sa[0]),
					Integer.parseInt(sa[1]),
					Integer.parseInt(sa[2]),
				};
			
			if(edge[0]+edge[1]>edge[2]){
				if(edge[0]==edge[1] )lozenge++;
				if(edge[0]*edge[0]+edge[1]*edge[1]
						==edge[2]*edge[2])rect++;
			}
		}
		ln(rect);
		ln(lozenge);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		for (int i = 1; i < s.length(); i++) {
			if (i % 2 == 1)
				continue;
			int checkLen = s.length() - i;
			String check = s.substring(0, checkLen);
			String mae = check.substring(0, check.length()/2);
			String usiro = check.substring(check.length()/2, check.length());
			if(mae.equals(usiro)){
				System.out.println(s.length() - i);
				break;
			}
		}

		sc.close();
	}

}

Measured memory_bytes: 21972
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;





int main()
{
    char ch1,ch2,ch3;
    ch1=getchar();ch2=getchar();ch3=getchar();

    if (ch1=='S'){
        if (ch2=='U')
            printf("7");
        else
            printf("1");
    }
    else
    if (ch1=='M')
        printf("6");
    else
    if (ch1=='W')
        printf("4");
    else
        if (ch1=='F')
        printf("2");
    else
    {
        if (ch2=='U')
            printf("5");
        else
            printf("3");
    }


}



Measured memory_bytes: 128
#include <cstdio>
#include <unordered_map>
#include <deque>
#include <algorithm>
using namespace std;
typedef int key;

int main(){
	int r,c,n;
	scanf("%d%d%d",&r,&c,&n);
	unordered_map<key,deque<pair<key,long long>>>m;
	for(;n;n--){
		int s1,s2,d;
		scanf("%d%d%d",&s1,&s2,&d);
		m[s1].emplace_back(s2+r,d);
		m[s2+r].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		long long a=-1LL<<61,b=1LL<<61;
		auto s=m.begin()->first;
		deque<pair<key,long long>>st={{s,0}};
		unordered_map<key,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.begin();st.pop_front();
			auto cur=p.first;long long d=p.second;
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
					memo[e.first]=d+e.second;
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return 0;
				}
			}
			if(cur<=r)a=max(a,d);
			else b=min(b,d);
		}
		if(a>b){
			puts("No");
			return 0;
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}

Measured memory_bytes: 142920
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		char ch=sc.next().charAt(0);
		int b=sc.nextInt();
		if(ch=='+')System.out.println(a+b);
		else System.out.println(a-b);
		sc.close();
	}
}


Measured memory_bytes: 35648
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

cups = {'A': 1, 'B': 0, 'C': 0}

for line in stdin:
    t, s = line.strip().split(',')
    cups[t], cups[s] = cups[s], cups[t]

for c in 'ABC':
    if cups[c]:
        print(c)
        break

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n;
    cin >> n;
    string s;
    cin >> s;
    
    i32 ans = 0;
    for (i32 l = 0; l < n; l++) {
        i32 m = n-l;
        vector<i32> z(m);
        z[0] = m;

        for (i32 i = 1, j = 0; i < m;) {
            while (i+j < m && s[l+j] == s[l+i+j]) j++;
            z[i] = j;

            if (j == 0) {
                i++;
                continue;
            }

            i32 k = 1;
            while (k < j && k+z[k] < j) {
                z[i+k] = z[k];
                k++;
            }

            i += k, j -= k;
        }

        for (i32 i = 1; i < m; i++) {
            if (z[i] <= i) ans = max(ans, z[i]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256