akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, int> pi;
typedef long long lint;
const int MAXN = 20005;

int n, a[MAXN], b[MAXN];
lint sa, sb, sc;

int main(){
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	for(int i=0; i<n; i++){
		sa += a[i];
		sb += b[i];
		if(a[i] > b[i]) sc += a[i];
		else sc += (b[i] % 2 == a[i] % 2 ? b[i] : (b[i] + 1));
	}
	if((sb - sa) >= (sc - sb)) puts("Yes");
	else puts("No");
}


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

R = []

for i in range(0,n):
    R.insert(i, int(input()))

maxV = -2000000000  # ????°??????????????????????????¨????????????????
minV = R[0]

for r in range(1, n):
    maxV = max(maxV, R[r] - minV)
    minV = min(minV, R[r])

print(maxV)

Measured memory_bytes: 15588
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==5&&b==5&&c==7)
	{
		printf("YES");
	}
	else if(a==5&&b==7&&c==5)
	{
		printf("YES");
	}
	else if(a==7&&b==5&&c==5)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
	return 0;
}

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

s=[0]*n
s[0]=a[0]%m
for i in range(1,n):
    s[i]=(s[i-1]+a[i])%m
    
t=dict()
for i in range(n):
    si=s[i]
    if si in t:
        t[si]+=1
    elif si==0:
        t[0]=2
    else:
        t[si]=1
        
icnt=0
for v in t.values():
    icnt+=v*(v-1)//2

print(icnt)


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

int main()
{
	float a,b,c=0,d=0;
	while(1){
		cin>>a;
		cin>>b;
		if(a==c&&b==d)
			return 0;
		cout<<(int)log10(a+b)+1<<endl;
		c=a;
		d=b;
	}
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double

using namespace std;

int h, w, n;
int a[10010], c[101][101];

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

bool check(int x, int y) {
	return x >= 1 && x <= h && y >= 1 && y <= w && c[x][y] == 0;
}

int main() {
	cin >> h >> w >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];

	int x = 1, y = 1, d = 0;
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < a[i]; j++) {
			c[x][y] = i;
			cnt++;
			if(cnt == h * w) break;
			int nx = x + dx[d];
			int ny = y + dy[d];
			// cerr << x << " " << y << endl;
			while(!check(nx, ny)) {
				d++;
				d %= 4;
				nx = x + dx[d];
				ny = y + dy[d];
				// cerr << "shit\n";
			}
			x = nx, y = ny;
		}
	}

	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			cout << c[i][j] << " ";
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
          int a;
          string s;
          cin >> a >> s;
          if(a>=3200)
          {
                 cout << s << endl;   
          }
          else
          {
                    cout << "red" << endl;
          }
          return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    int minm=500,maxm=-500;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        maxm=max(maxm,a[i]);
        minm=min(minm,a[i]);
    }
    int ans=1e8,cost=0;
    for(int i=minm;i<=maxm;i++)
    {
        for(int j=0;j<n;j++)
        {
            int y=abs(i-a[j]);
            cost+=y*y;
        }
        ans=min(ans,cost);
        cost=0;
    }
    cout<<ans;
    return 0;
}







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

using namespace std;

int main()
{
    int N;
    int T,A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for (int i = 0;i < N;i++) {
        cin >> H[i];
    }
    int ans = 0;
    double co = 100000000;
    for (int i = 0;i < N;i++) {
        if(abs(A -(T - H[i]*0.006)) < co){
            co = abs(A - (T - H[i]*0.006));
            ans = i + 1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  vi a(n);
  rep(i, n) cin >> a[i];

  vvi b(n, vi(n, inf));
  rep(i, n){
    rep(j, n){
      if(j == 0) b[i][j] = a[i];
      else b[i][j] = min(b[i][(j-1+n)%n], a[(i-j+n)%n]);
//    cout << b[i][j] << " ";
    }
//    cout << endl;
  }

  ll ans = linf;
  rep(i, n){
    ll t = (ll)i*x;
    rep(j, n){
      t += b[j][i];
    }
    ans = min(ans, t);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16000
program main
	implicit none
    integer(8)::n,i,j,k,b,c
    integer(8),allocatable::a(:)
    read(*,*)n
    allocate(a(n))
    read(*,*) a
    call heapsort(n,a)
    !write(*,*) a
    k=a(n)
    b=0
    c=0
    do i=n-1,1,-1
    	if(a(i)==k)then
        	if (b==0)then
        		b=k
                k=0
            else if(c==0)then
            	c=k
                k=0
            end if
        else
        	k=a(i)
        end if
    end do
    write(*,*) c*b
    
    deallocate(a)
    stop
contains
subroutine heapsort(n,array)
        implicit none
        integer(8),intent(in) :: n
        integer(8),intent(inout) :: array(1:n)
       
        integer ::i,k,j,l
        double precision :: t
       
        if(n.le.0)then
           write(6,*)"Error, at heapsort"; stop
        endif
        if(n.eq.1)return
      
        l=n/2+1
        k=n
        do while(k.ne.1)
           if(l.gt.1)then
              l=l-1
              t=array(L)
           else
              t=array(k)
              array(k)=array(1)
              k=k-1
              if(k.eq.1) then
                 array(1)=t
                 exit
              endif
           endif
           i=l
           j=l+l
           do while(j.le.k)
              if(j.lt.k)then
                 if(array(j).lt.array(j+1))j=j+1
              endif
              if (t.lt.array(j))then
                 array(i)=array(j)
                 i=j
                 j=j+j
              else
                 j=k+1
              endif
           enddo
           array(i)=t
        enddo
      
        return
    end subroutine heapsort
end program main




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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables **************/
int n;
vector<int> a;
map<int, int> mp;
int ans = 0;
/**********************************************/

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

    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];

    sort(all(a));
    REP(i, n) mp[a[i]]++;
    REP(i, mp.size()) ans++;
    
    for(auto x: mp){
        if(x.second >= 3){
            mp[x.first] = (x.second % 2 == 0 ? 1: 0) + 1;
        }
    }

    int nokori = 0;
    for(auto x: mp){
        if(x.second > 1){
            int num = x.second - 1;
            nokori = abs(num - nokori);
        }
    }
    cout << ans - nokori << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N;cin>>N;
  vll A(N);rep(i,N)cin>>A[i];
  ll ans=0;
  map<ll,ll> m;
  rep(i,N){
    m[i-A[i]]++;
  }
  rep(i,N){
    if(m[i+A[i]]>0){
      ll t = m[i+A[i]];
      ans += t;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 27384
#include <stdio.h>

typedef struct {
	double x;
	double y;
} Coord;

double area_poly( Coord *coord, int n ) {
	int i;
	double sum = 0.0;

	for ( i = 1; i <= n; i++ )
		sum += coord[ i - 1 ].x * coord[ i % n ].y - coord[ i - 1 ].y * coord[ i % n ].x;

	return -sum / 2.0;
}

int main( void ) {
	int i;
	int n, cnt;
	Coord coord[ 100 ];

	cnt = 0;
	while ( scanf( "%d", &n ), n ) {
		for ( i = 0; i < n; i++ )
			scanf( "%lf %lf", &coord[ i ].x, &coord[ i ].y );

		printf( "%d %.1f\n", ++cnt, area_poly( coord, n ) );
	}

	return 0;
}

Measured memory_bytes: 656
n = input()

l = len(n)
if l == 1:
    print(int(n))
elif l == 2:
    print(9)
elif l == 3:
    print(9+int(n)-99)
elif l == 4:
    print(9+900)
elif l == 5:
    print(9+900+int(n)-9999)
elif l == 6:
    print(9+900+90000)



Measured memory_bytes: 38384
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
    string S;
    cin >> S;
    
    int flag = 0;
    for(int i=1; i<(int)S.size(); i++){
        if(S[i-1] == S[i]) flag = 1;
    }

    if(flag){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }

    return 0;
}


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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i);

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, a[1000001];
    cin >> n;
    for (llong i = 0; i < n * 3; ++i) {
        cin >> a[i];
    }
    sort(a, a + n * 3, greater<llong>());

    llong ans = 0;
    for (llong i = 0; i < n; ++i) {
        //cout << 2 * i + 1 << endl;
        ans += a[2 * i + 1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long maximum;
long long mod = 1000000007;
const int INF = 1001001001;
vector<vector<int>> dp;

int main(){
 int h,w;
 cin >> h >> w;
 vector<vector<int>> c(10,vector<int>(10));
 vector<vector<int>> A(h,vector<int>(w));
 for(int i=0;i<10;i++){
   for(int j=0;j<10;j++){
     int input; cin >> input;
     c.at(i).at(j) = input;
   }
 }
 for(int k = 0;k<10;k++){
   for(int i=0;i<10;i++){
     for(int j=0;j<10;j++){
       c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k)+c.at(k).at(j));
     }
   }
 }
 int ans;
 for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
     int input; cin>>input;
     if(input!=-1) ans += c.at(input).at(1);
   }
 }
 cout << ans << endl; 
}


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

int main() {
	int h1, w1, h2, w2, ans = 0;

	cin >> h1 >> w1;
	cin >> h2 >> w2;

	ans = h1 * w1 - h1 * w2 - h2 * w1 + h2 * w2;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


void energy_drink_collector()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> ab(n);
  for (int i = 0; i < n; ++i) cin >> ab[i].first >> ab[i].second;

  sort(ab.begin(), ab.end());

  long long int total_fee = 0;
  for (int i = 0; i < n && m > 0; ++i)
  {
    total_fee += (long long int)ab[i].first * (long long int)min(m, ab[i].second);
    m -= min(m, ab[i].second);
  }

  cout << total_fee << "\n";
}


void get_AC()
{
  int n, q;
  string S;
  cin >> n >> q >> S;

  vector<int> cnt(n + 1);
  for (int i = 0; i < n; ++i)
  {
    if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') cnt[i + 1] = cnt[i] + 1;
    else cnt[i + 1] = cnt[i];
  }

  for (int i = 0; i < q; ++i)
  {
    int l, r;
    cin >> l >> r;
    cout << cnt[r - 1] - cnt[l - 1] << "\n";
  }
}


int main()
{
  //energy_drink_collector();
  get_AC();

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long n,m,s,a[100000];
int main()
{
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(s>n)cout<<-1;
    else cout<<n-s;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
// 82

using namespace std;

const int MOD = (int) 1e9 + 7;
const int MAXN = (int) 1e5;

ll sp[100];
int p10[MAXN + 1];

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1)
            ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, s, d;
    ios::sync_with_stdio(false);
    cin >> s;
    p10[0] = 1;
    for(i = 1; i <= MAXN; i++) {
        p10[i] = (1LL * p10[i - 1] * 10) % MOD;
    }
    for(i = 1; i <= 15; i++) {
        sp[i] = sp[i - 1] + 1LL * i * 9 * p10[i - 1];
    }
    int ans = 0;
    for(d = 1; d * d <= s; d++) {
        if(s % d == 0) {
            if(s / d <= 1LL * 9 * p10[d - 1] || d > 9) {
                ans = (ans + 1LL * 9 * p10[d - 1] - s / d + 1) % MOD;
            }
            if(d * d < s) {
                int a = lgput(10, s / d - 1);
                if(d <= 1LL * 9 * a || s / d > 9) {
                     ans = (ans + 1LL * 9 * a - d + 1) % MOD;
                }
            }
        }
    }
    for(i = 1; i <= 7; i++) {
        int dim = 9 * p10[i - 1];
        int sum = 0;
        for(int j = 1; j <= dim && sum + i < s; j++) {
            sum += i;
            int rez = 0;
            for(int pas = 1 << 5; pas; pas >>= 1) {
                if(rez + pas <= 8 && sp[rez + pas] - sp[i] + sum <= s)
                    rez += pas;
            }
            if((s - sum - (sp[rez] - sp[i])) % (rez + 1) == 0) {
                ans++;
            }
        }
    }
    for(i = 1; i <= s / 8; i++) {
        if(s % i)
            ans++;
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

vector<pair<int,int> > ary[10001];

int main(){ _;
  int N,M,t,n,m,s,r,q,ts,te;
  while(cin>>N>>M,(N|M)!=0){
    cin>>r;
    REP(i,r){
      cin>>t>>n>>m>>s;
      ary[m].push_back(make_pair(t,s==1?1:-1));
    }
    cin>>q;
    REP(i,q){
      cin>>ts>>te>>m;
      map<int,int> a;
      for(auto p:ary[m]){
	if(p.first<ts)
	  a[ts]+=p.second;
	else if(p.first>te)
	  a[te]+=p.second;
	else
	  a[p.first]+=p.second;
      }
      int sum=0,start=0,login=0;
      for(auto aa:a){
	if(login==0&&aa.second>0){
	  start=aa.first;
	}
	login+=aa.second;
	if(login==0&&aa.second<0){
	  sum+=aa.first-start;
	}
      }
      cout<<sum<<endl;
    }
    REP(i,M+1){
      ary[i].clear();
    }
  }
}

Measured memory_bytes: 1536
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]

ans = 0
for i in range(N):
    sum = 0
    for j in range(N):
        if j <= i:
            sum += A[0][j]
        if j >= i:
            sum += A[1][j]
    ans = max(ans, sum)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int a[100050];
    map<int, int> m;
    cin >> n;
    for(int i = 0;i < n;i++){
        int x;
        cin >> x;
        m[x]++;
    }
    int ans = 0;
    for(auto&& p:m){
        ans += p.second - p.first * (p.second >= p.first);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    VI v;
    REP(i,3*n) {
        long a;
        cin >> a;
        v.push_back(a);
    }
    VI ma;
    priority_queue<long, VI, greater<long>> q;
    long sum = 0;
    REP(i,n) {
        q.push(v[i]);
        sum += v[i];
    }
    ma.push_back(sum);
    REPI(i,n,2*n) {
        if (v[i] > q.top()) {
            sum -= q.top();
            q.pop();
            q.push(v[i]);
            sum += v[i];
        }
        ma.push_back(sum);
    }
    
    VI mi;
    priority_queue<long> qu;
    sum = 0;
    REPI(i,2*n,3*n) {
        qu.push(v[i]);
        sum += v[i];
    }
    mi.push_back(sum);
    for (int i = 2 * n - 1; i >= n; i--) {
        if (v[i] < qu.top()) {
            sum -= qu.top();
            qu.pop();
            qu.push(v[i]);
            sum += v[i];
        }
        mi.push_back(sum);
    }
    long ans = -1e18;
    REP(i,n+1) {
        ans = max(ans, ma[i] - mi[n-i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8428
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	int n;
	cin >> n;
	VI a(n);
	rep(i, n) cin >> a[i];

	int sum = 0;
	rep(i, n) {
		sum += a[i];
	}
	
	sort(all(a));

	int mem = sum;
	rep(i, n) {
		if (sum % 10 == 0) {
			if (a[i] % 10 != 0) {
				sum -= a[i];
			}
		} else {
			cout << sum << endl;
			return 0;
		}
	}

	if (mem == sum) {
		cout << 0 << endl;
	}
	
	return 0;
}


 

Measured memory_bytes: 256
import math

K = int(input())

g = []
for i in range(1, K+1):
    for j in range(1, K+1):
        g.append(math.gcd(i, j))

result = 0
for i in range(1, K+1):
    for t in g:
        result += math.gcd(i, t)

print(result)



Measured memory_bytes: 70368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Point {
    double x;
    double y;

    void print() {
        System.out.printf("%.8f %.8f\n", x, y);
    }
}

public class Main {
    static final double ONE_THIRDS_PI = Math.PI * 60 / 180;
    static final double SIN60 = Math.sin(ONE_THIRDS_PI);
    static final double COS60 = Math.cos(ONE_THIRDS_PI);

    static void koch(int d, Point p1, Point p2) {
        if (d == 0) return;

        Point s = new Point();
        Point u = new Point();
        Point t = new Point();

        s.x = (2 * p1.x + 1 * p2.x) / 3;
        s.y = (2 * p1.y + 1 * p2.y) / 3;
        t.x = (1 * p1.x + 2 * p2.x) / 3;
        t.y = (1 * p1.y + 2 * p2.y) / 3;
        u.x = (t.x - s.x) * COS60 - (t.y - s.y) * SIN60 + s.x;
        u.y = (t.x - s.x) * SIN60 + (t.y - s.y) * COS60 + s.y;

        koch(d - 1, p1, s);
        s.print();
        koch(d - 1, s, u);
        u.print();
        koch(d - 1, u, t);
        t.print();
        koch(d - 1, t, p2);
    }

    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(in.readLine());

            Point p1 = new Point();
            Point p2 = new Point();

            p1.x = 0;
            p1.y = 0;
            p2.x = 100;
            p2.y = 0;

            p1.print();
            koch(n, p1, p2);
            p2.print();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,c=0,sum=0;
    c_p_c();
   	ll a,b,x;
   	cin>>a>>b>>x;
   	ll ans  = a / x;
   	ll ans1=b/x;
   	if(a%x==0) cout<<ans1-ans+1<<endl;
   	else cout<<ans1-ans<<endl;}

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


int main(){
  int N;
  cin>>N;
  int p=-1;
  int a[N];
  int ans = 0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    if(a[i] == p){
      ans++;
      p=-1;
    }
    else p=a[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
def f(h, w, n):
    si, sj = map(int, input().split())
    ss = input()
    tt = input()
    l = u = 1
    r, d = w, h
    for t, s in zip(tt[::-1], ss[::-1]):
        if t == "U" and d < h:
            d += 1
        elif t == "D" and u > 1:
            u -= 1
        elif t == "L" and r < w:
            r += 1
        elif t == "R" and l > 1:
            l -= 1
        if s == "U":
            u += 1
        elif s == "D":
            d -= 1
        elif s == "L":
            l += 1
        else:
            r -= 1
        if u > d or l > r:
            print("NO")
            exit()
    if u <= si <= d and l <= sj <= r:
        print("YES")
    else:
        print("NO")


h, w, n = map(int, input().split())
f(h, w, n)


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
char s[N];
int sa;
ll ans;

int main() {
	scanf("%s",s);
	int n=strlen(s);
	for (int i=0;i<n;i++) {
		if (s[i]=='B') {
			if (s[i+1]=='C') {
				ans+=sa;
				i++;
			} else {
				sa=0;
			}
		} else if (s[i]=='C') {
			sa=0;
		} else if (s[i]=='A') sa++;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 512
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)



        
def main(): #startline--------------------------------------------
    N,W = map(int,input().split())
    wv = [list(map(int,input().split())) for i in range(N)]
    w = [wv[i][0] for i in range(N)]
    v = [wv[i][1] for i in range(N)]
    dp = [[0]*(W+1) for i in range(N+1)]
    for i in range(W+1):
        dp[N][i] = 0
    for i in reversed(range(N)):
        for j in range(W+1):
            if j < w[i]:
                dp[i][j] = dp[i+1][j]
            else:
                dp[i][j] = max(dp[i+1][j],dp[i+1][j-w[i]]+v[i])

    print(dp[0][W])
if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 123656
/* _________________________________________________________________________________________________
  |                                                                                                 |
  |                             Author      : Aditya Ahuja                                          |
  |                             Date        : Thu, 20th Jun 2019                                    |
  |_________________________________________________________________________________________________|
*/
 
#include<bits/stdc++.h>
using namespace std;

// #define int long long

#define pb          push_back
#define F           first
#define S           second
#define rep(i,a,b)  for(int i=a; i<b; i++)
#define all(a)      (a).begin(),(a).end()
#define ret(x)      {cout << (x) << endl; return;}
#define sz(x)       (int)x.size()
#define type(x)     typeid(x).name()

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

#define wa(x)       cout << (#x) << " -------- " << (x) << endl
#define pvi(v)      {for(auto it:v) cout << it << " "; cout << endl;}
#define line1	    printf("---------------------------\n")

// #define wa //
// #define line1 //
// #define pvi //
// #define printf //

void solve();
signed main() {
	//ios_base::sync_with_stdio(false); cin.tie(NULL);
	////cout << fixed << setprecision(10);

	int t=1; 
	//cin>>t;
	while(t--) solve();
	return 0;
}

//___________________________________________________________________________________________________

void solve() {

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

	vi a(n);
	rep(i,0,n) cin >> a[i];

	vi dp(k+1,0);

	rep(i,1,k+1){
		rep(j,0,n){
			if(i >= a[j] && !dp[i - a[j]]) dp[i]=1;
		}
	}

	cout << (dp[k] ? "First" : "Second") << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define repr(i,k,n) for (i = k; i >= n; --i) 
#define F first;
#define S second;
#define PB push_back;
#define MP make_pair;
// #define ll long long;
#define show(x) cerr << #x << " is " << x << endl;

using namespace std;

typedef vector<int> vi; 
typedef pair<int, int> pll;
typedef long long ll;
typedef unsigned long long ull;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t;
    cin >> t;
    ll res = t*t;
    cout << res << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll n,w;
int main()
{
    cin>>n>>w;
    pair<ll,ll>a[n];
    ll maxval=n*1000;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].second>>a[i].first;
        
    }
    //ll ans=0;
    ll dp[n][maxval+1];
    dp[0][0]=0;
    for(int i=1;i<=maxval;i++)
    {
        dp[0][i]=INT_MAX;
    }
    dp[0][a[0].first]=a[0].second;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=maxval;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=a[i].first)
            dp[i][j]=min(dp[i][j],a[i].second+dp[i-1][j-a[i].first]);
        }
    }
    ll ans=0;
    //cout<<w<<endl;
    //cout<<n<<" ";
    for(int i=0;i<=maxval;i++)
    {
       if(dp[n-1][i]<=w)
       ans=i;
    }
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<=maxval;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<ans<<endl;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

vector<vector<vector<int>>> dp(90, vector<vector<int>>(90, vector<int>(25700)));
vector<vector<int>> A(90, vector<int>(90));
vector<vector<int>> B(90, vector<int>(90));


int main() {
    ll n; cin >> n;
    if(n % 2 == 1ll) {
        cout << 0 << endl;
        return 0;
    }
    ll res = 0;
    n /= 2ll;
    while(n > 0) {
       n /= 5ll;
       res += n;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 825692
#include <iostream>
using namespace std;
void countingSort(int *a, int *b, int k, int n){
	int *c = new int[k+1];
	for(int i=0;i<k+1;++i)c[i] = 0;
	for(int j=0;j<n;++j)c[a[j]]++;
	for(int i=1;i<k+1;++i)c[i] += c[i-1];
	for(int j=n-1;j>=0;--j){
		b[c[a[j]]-1] = a[j];
		c[a[j]]--;
	}
}

int max(int *a, int n){
	int m = 0;
	for(int i=0;i<n;++i){
		if(m<a[i])m=a[i];
	}
	return m;
}

int main() {
	int n, *a, *b, k;
	cin>>n;
	a = new int[n];
	b = new int[n];
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	k = max(a,n);
	countingSort(a,b,k,n);
	for(int i=0;i<n;++i){
		cout<<(i?" ":"")<<b[i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 16860
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll ans;
ll N, K;
ll A[100001];

long long Pow(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}


int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> K;

	
	
	for (ll i = 1; i <= K; i++) {
		
		ll num = K / i;
		A[i] = Pow(num, N);
	}

	for (int i = K; i >= 1; i--) {
		for (int j = i * 2; j <= K; j += i) {
			(A[i] -= A[j]) %= MOD;
		}
	}
	
	for (int i = 1; i <= K; i++) {
		(ans += (A[i] * i) % MOD) %= MOD;
	}
	ans += MOD;
	ans %= MOD;
	cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 4432
#include <stdio.h>
int solve(int n)
{
    if (n <= 0) {
        return 1;
    }
    else {
        return solve(n-1)+n;
    }
}
int main()
{
    int n;
    while (scanf("%d", &n) != EOF) {
        printf("%d\n", solve(n));
    }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;

int main(){
  int ans=0;
  string s,t;
  cin >> s >> t;
  
  REP(i,s.size()){
    if(s.at(i)!=t.at(i))ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n + 1) cin >> a[i];
    if (n == 0) {
        if (a[0] == 1) {
            cout << 1 << endl;
        }
        else {
            cout << -1 << endl;
        }
        return 0;
    }
    vector<ll> dp(n + 2, 0);
    rrep(i, n + 1) dp[i] += dp[i + 1] + a[i];
    ll ans = 0, cv = 1;
    rep(i, n + 1) {
        if (cv < a[i]) {
            cout << -1 << endl;
            return 0;
        }
        cv = min(cv, dp[i]);
        ans += cv;
        cv -= a[i];
        cv *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 long double h;
 cin >> h;
 int a=(int)log2(h);
 cout << std::setprecision(15) << pow(2,a+1)-1;
 return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   string s, t;
   cin>>s>>t;

   int mn=INT_MAX;
   rep(i, s.size()-t.size()+1){
      int c=0;
      rep(j, t.size()){
         if(s[i+j]!=t[j]) c++;
      }
      mn=min(mn, c);
   }

   cout<<mn<<endl;
   return 0;
}


Measured memory_bytes: 3624
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s = v()

s1,s2,s3 = set(),set(),set()
for x in s:
    for z in s2:
        s3.add(z+x)
    for y in s1:
        s2.add(y+x)
    s1.add(x)
print(len(s3))



Measured memory_bytes: 10568
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 d = sc.nextInt();
  int e = c-(d-b);
  int f = d+(c-a);
  System.out.print(e);
  System.out.print(" ");
  System.out.print(f);
  System.out.print(" ");
  System.out.print(e-(c-a));
  System.out.print(" ");
  System.out.print(f-(d-b));
  System.out.println("");
}}

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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int last[26];


int main() {
    int n;
    string s;
    pair<int, int> ans = {-1, -1};
    cin >> s;
    n = s.size();
    fill(last, last + 26, -1);
    for (int i = 0; i < n; i++) {
        if (last[s[i] - 'a'] >= 0) {
            if (i - last[s[i] - 'a'] < 3) {
                ans.first = last[s[i] - 'a'] + 1;
                ans.second = i + 1;
                break;
            }
            last[s[i] - 'a'] = i;
        } else
            last[s[i] - 'a'] = i;
    }
    cout << ans.first << ' ' << ans.second;
}

Measured memory_bytes: 512
n = int(input())
flag = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if(d1 == d2):
        flag += 1
        if(flag == 3):
            break
    else:
        flag = 0
if(flag == 3):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62364
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct Team {
    int number, correct, penalty;

    bool operator <(const Team &t) const {
        if(correct != t.correct) return correct > t.correct;
        if(penalty != t.penalty) return penalty < t.penalty;
        return number < t.number;
    }
};

int main() {
    while(true) {
        int T, P, R;
        cin >> T >> P >> R;
        if(!T && !P && !R) break;

        vector<Team> teams(T);
        for(int i = 0; i < T; ++i) teams[i].number = i+1;
        vector<vector<int> > wa_count(T, vector<int>(P, 0));

        for(int i = 0; i < R; ++i) {
            int tid, pid, tim;
            string message;
            cin >> tid >> pid >> tim >> message;
            --tid; --pid;
            if(message == "CORRECT") {
                teams[tid].correct++;
                teams[tid].penalty += tim + wa_count[tid][pid] * 1200;
            }
            else {
                wa_count[tid][pid]++;
            }
        }

        sort(teams.begin(), teams.end());
        for(int i = 0; i < teams.size(); ++i) {
            cout << teams[i].number << ' ' << teams[i].correct << ' ' << teams[i].penalty << endl;
        }
    }

    return 0;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	ll n, q;
	cin >> n >> q;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	rep(i,q){
		ll k;
		cin >> k;
		//kを超えないようにする時の最大

		ll ans = 0;
		ll right = 0;
		ll sum = 0;
		for(ll left = 0; left < n; left++){
			if(right < left) right = left;
			while(right < n && sum + a[right] <= k){
				sum += a[right];
				right ++;
			}
			ans += right - left;
			if(left < right){
				sum -= a[left];
			}
		}
		cout << ans << endl;
	}
}



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

#define int long long


long long a[500][500] = {};
signed main(){

    int n;

    cin >> n;

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

    bool memo[500][500] = {};
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < n;k++){
                if(a[j][k] > a[j][i] + a[i][k]){
                    cout << -1 << endl;
                    return 0;
                }else if((a[j][k] == a[j][i] + a[i][k]) && j != i && i != k){
                    memo[j][k] = true;
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(!memo[i][j]){
                ans += a[i][j];
            }
        }
    }

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


Measured memory_bytes: 1664
integer(8)::a(9)=(/1,2,4,7,12,20,29,38,52/),f(10)=0
read(*,*)n
f(3)=1
do i=4,n
 f(i)=f(i-1)*(a(i-2)+a(i-3)+1)
enddo
do i=1,n
 do j=1,n
  write(*,*)merge(0_8,f(max(i,j))*a(min(i,j))+1,i==j)
 enddo
enddo
end

Measured memory_bytes: 256
N,Q=gets.split.map(&:to_i)
AB=(N-1).times.map{gets.split.map(&:to_i)}.sort_by{|a|a[0]}
PX=Q.times.map{gets.split.map(&:to_i)}

g=Array.new(N){[]}
AB.each do |a, b|
  g[a-1] << b-1
  g[b-1] << a-1
end

checked = Array.new(N, false)
parent = Array.new(N, -1)
zyunban=[]
checked[0] = true
queue = []
g[0].each do |n|
  queue << [0, n]
end
while que = queue.shift
  par, chi = que
  checked[chi] = true
  parent[chi] = par
  zyunban << chi
  
  npar = chi
  g[npar].each do |nchi|
    next if checked[nchi]
    queue << [npar, nchi]
  end
end

ans=Array.new(N, 0)
PX.each do |p, x|
  ans[p-1] += x
end

zyunban.each do |i|
  ans[i] += ans[parent[i]]
end

puts ans.join(" ")

Measured memory_bytes: 63012
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


a,b,k = LI()
cnt = 0
for i in range(1,max(a,b)+1)[::-1]:
    if a % i == 0 and b % i == 0:
        cnt += 1
    if cnt == k:
        print(i)
        quit()

Measured memory_bytes: 38256
n = int(input())
judge = [0]*n
for _ in range(n):
  judge[_] = input()
# print(judge.count('AC'))

ac, wa, tle, re = 0, 0, 0, 0
for c in judge:
  if c=='AC':
    ac += 1
  elif c=='WA':
    wa += 1
  elif c=='TLE':
    tle += 1
re = n - (ac+wa+tle)
# print(ac, wa, tle, re)
judges = [ac, wa, tle, re]
judge_c = ["AC","WA","TLE","RE"]
for i in range(len(judge_c)):
  print(f'{judge_c[i]} x {judges[i]}')

Measured memory_bytes: 15872
// Problem : B - Postal Code
// Contest : AtCoder - AtCoder Beginner Contest 084
// URL : https://atcoder.jp/contests/abc084/tasks/abc084_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

void solve()
{
int a,b;cin>>a>>b;
string s;cin>>s;
if(size(s)==a+b+1 and s[a]=='-')
{
	int cnt=0;
	for(char c:s)
	cnt+=(c>='0' and c<='9');
	if(cnt==a+b)
	cout<<"Yes";
	else
	cout<<"No";
}
else
cout<<"No";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3596
sd = input()
t = input()

def compaierStr(expected: list, actual: list) -> bool:
    for e, a in zip(expected, actual):
        if e != a and a != "?":
            return False

    return True

candidates = []
for i in range(len(sd)-len(t)+1):
    if compaierStr(t, sd[i:i+len(t)]):
        candidates.append((sd[:i] + t + sd[i+len(t):]).replace("?", "a"))

if len(candidates) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(candidates)[0])


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
#include <iomanip>
#include <cmath>
#define PI acos(-1)
typedef long long ll;
const long long mod = 998244353;
const long long maxn = 1e9 + 5; 
using namespace std;

int main()
{
	string s, ss;
	cin >> s >> ss;
	int len = s.length();
	int flag = 1;
	for (int i = 0; i < len; i++)
	{
		if (s[i] != ss[i])
		{
			flag = 0;
			break;
		}
	}
	if (flag && ss.length() == len + 1)
	{
		printf("Yes\n");
	}
	else 
		printf("No\n");
	return 0;	
} 

Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 21;

int dx[4] = {1, -1, 0 ,0};
int dy[4] = {0, 0, 1, -1};
bool mat[maxn][maxn];
int n, m, d[maxn][maxn];

bool can(int r, int c){
	return (r>=0 && r<n && c>=0 && c<m && mat[r][c] == 1 && d[r][c] == -1);
}

int mbfs(pair<int,int> start){
	memset(d, -1, sizeof(d));
	queue<pair<int,int>> q; q.push(start);
	d[start.first][start.second] = 0;
	int mx = 0;
	while(q.size()){
		int r = q.front().first, c = q.front().second;
		mx = max(d[r][c], mx);
		q.pop();
		for(int i = 0; i<4; i++) if (can(r+dx[i], c+dy[i])){
			int nr = r+dx[i], nc = c+dy[i];
			d[nr][nc] = d[r][c]+1;
			q.push({nr, nc});
		}
	}
	return mx;
}

int main(){
	cin >> n >> m;
	for(int i = 0; i<n; i++){
		string s; cin >> s;
		for(int j = 0; j<m; j++) if (s[j] == '.') mat[i][j] = 1; 
	}
	int ans = 0;
	for(int i = 0; i<n; i++){
		for(int j = 0; j<m; j++) if (mat[i][j]) ans = max(ans, mbfs({i, j}));
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256