akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
    #include <string>
    #include <math.h>
    #include<algorithm>
    using namespace std;
     
    int main(){
      int H, W;
      cin >> H >> W;
      char a[H][W];
      for(int i=0;i<H;i++){
       for(int j=0;j<W;j++){
        cin >> a[i][j]; 
       }
      }
      for(int i=0;i<H;i++){
       for(int j=0;j<W;j++){
         bool flag1=true;
         bool flag2=true;
         for(int k=0;k<W;k++){
          if(a[i][k]=='#'){
           flag1=false; 
          }
         }
         for(int k=0;k<H;k++){
           if(a[k][j]=='#'){
            flag2=false; 
           }
         }
           if(flag1==false && flag2==false){
            cout << a[i][j]; 
           }
        if(j==W-1 &&( flag1==false || flag2==false) ){
         cout << endl; 
        }
         }
       }

      return 0;}

Measured memory_bytes: 256
#include<stdio.h>
int max(int a,int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

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

int main(void){
    int n,i,j;
    int a[200000];
    int maxv=-2000000000;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int minv=a[0];
    for(i=0;i<n;i++){
        for(i=1;i<n;i++){
            maxv=max(maxv,a[i]-minv);
            minv=min(minv,a[i]);
        }
    }
    printf("%d\n",maxv);

    return 0;
}


Measured memory_bytes: 2628
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int main()
{
	int n; cin>>n;
	if(n%2==1) cout<<(n+1)/2;
	else cout<<n/2;
	return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int bill = 4;
		int floor = 3;
		int room = 10;

		int [][][] box = new int[bill][floor][room];

		Scanner sc = new Scanner(System.in);
		int max = sc.nextInt();
		//System.out.println(max);
		
		for (int i = 0; i < max ;i++) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();
			//System.out.println(b + " " + f + " " + r + " "  + v);
			
			box[b-1][f-1][r-1] = box[b-1][f-1][r-1] + v;
		}

		//result
		for (int b = 0; b < bill; b++) {
			for (int f = 0; f < floor; f++) {
				for (int r = 0; r < room; r++) {
					System.out.print(" " + box[b][f][r]);
				}
				System.out.println("");
			}
			if (b < bill-1) {
				System.out.println("####################");
			}
		}
		
		
	}
}


Measured memory_bytes: 29712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
class modBinomial{
	long inv(long x){// p is a prime
		if(x==0) return 0;
		int i=0;long res=1;
		while((p-2)>=(1<<i)){
			if((p-2)&(1<<i)) (res*=x)%=p;
			i++; x=x*x%p;
		}return res;
	}
public:
	const long p=mod;
    long modfact(long n){//n! mod p
	    if(n>=p) return 0;
        long res=1;
	    rep(i,1,n+1) (res*=i)%=p;
	    return res;
    }
    long modperm(long n,long r){//nPr mod p
	    if(n-r>=p||r%p>n%p) return 0;
	    long res=1;
	    rep(i,n-r+1,n+1) (res*=i)%=p;
	    return res;
    }
    long modcomb(long n,long r){//nCr mod p
	    return (modperm(n,r)*inv(modfact(r)))%p;
    }
};
int main(){
	int N;cin>>N;
	int A[N];long cnt[N]={};
    long ans=1;
	rep(i,0,N){
		cin>>A[i];
        if(A[i]) (ans*=(cnt[A[i]-1]-cnt[A[i]]))%=mod;
        cnt[A[i]]++;
	}
    modBinomial mb;
    //print(cnt,N);
	cout<<(ans*mb.modperm(3,cnt[0]))%mod<<endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>

using namespace std;

char kalimat1[105];
char kalimat2[105];

int main(){
   int a,i;
   scanf("%d", &a);
   getchar();
   scanf("%s %s",kalimat1,kalimat2);
   getchar();
   for(i=0;i<a;i++){
      printf("%c%c",kalimat1[i],kalimat2[i]);
   }
   printf("\n");
}

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

int main() 
{
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());

  double tmp = (v[0] + v[1])/2.0;
  for (int i = 2; i < n; i++){
    tmp = (tmp + v[i])/2.0;
  }
  cout << tmp << endl;
  return 0;
}


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

typedef pair<long long, long long> data_t;

int main(){
  int H,W,N;
  cin>>W>>H>>N;
  int LeftEnd=0,RightEnd=W,top=H,LowerEnd=0;
  int x,y,a;
  for(int i=0;i<N;i++){
    cin>>x>>y>>a;
    if(a==1){
      LeftEnd=max(LeftEnd,x);
    }
    else if(a==2){
      RightEnd=min(RightEnd,x);
    }
    else if(a==3)
      LowerEnd=max(LowerEnd,y);
    else
      top=min(top,y);
  }
  int height=max(top-LowerEnd,0),width=max(RightEnd-LeftEnd,0);
  cout<<height*width<<endl;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

int main()
{
	int N, M, I, x, y;
	char d;
	bool xy[21][21];
	int xnow, ynow;
	while (scanf("%d", &N) && N) {
		memset(xy, false, sizeof(xy));
		xnow = 10, ynow = 10;
		for (int i = 0; i < N; i++) {
			scanf("%d%d", &x, &y);
			xy[x][y] = true;
		}
		scanf("%d\n", &M);
		xy[xnow][ynow] = false;
		for (int i = 0; i < M; i++) {
			scanf("%c%d\n", &d, &I);
			switch (d) {
			case 'N':
				for (int i = 0; i < I; i++)
					xy[xnow][++ynow] = false;
				break;
			case 'S':
				for (int i = 0; i < I; i++)
					xy[xnow][--ynow] = false;
				break;
			case 'E':
				for (int i = 0; i < I; i++)
					xy[++xnow][ynow] = false;
				break;
			case 'W':
				for (int i = 0; i < I; i++)
					xy[--xnow][ynow] = false;
				break;
			}
		}
		for (int i = 0; i < 21; i++) for (int j = 0; j < 21; j++)
				if (xy[i][j]) {
					printf("No\n");
					goto end;
				}
		printf("Yes\n");
	end:;
	}
	return 0;
}



Measured memory_bytes: 2048
import math

[a, b, C] = [float(x) for x in raw_input().split()]
C = math.radians(C)
c = math.sqrt(a ** 2.0 + b ** 2.0 - 2.0 * a * b * math.cos(C))
L = a + b + c
S = 0.5 * a * b * math.sin(C)
h = S / a * 2.0

print S, L, h

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

set<int> divisor(int n) {
  int t = sqrt(n);
  set<int> ret;
  for (int i = 1; i <= t; i++) {
    if (n % i == 0) {
      ret.insert(i);
      ret.insert(n / i);
    }
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, M;
  cin >> N >> M;
  if (M % N == 0) {
    cout << M / N << endl;
    return 0;
  }
  set<int> s = divisor(M);
  int max = 0;
  for (int x : s) {
    if (x <= M / N) {
      max = x;
    }
  }
  cout << max << endl;
}


Measured memory_bytes: 3656
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n,k=io()
s=set()
c=0
for _ in range(k):
    d=int(input())
    s.update(op())
for i in range(1,n+1):
    if i not in s:
        c+=1
print(c)

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

using namespace std;

int main(){
    long long int N,sum=0,hanbun=0,aa=0;
    cin >> N;
    vector<long long int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }

    for(int i=0;i<N;i++){
        hanbun += A[i];
        if(sum/2<=hanbun){
            aa = hanbun-A[i];
            break;
        }
    }

    cout << min(abs(sum-hanbun-hanbun),abs(sum-aa-aa)) << endl;
}

Measured memory_bytes: 1792
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let h: i64 = lines.next().unwrap().unwrap().parse().unwrap();
    let ans = count(h);
    println!("{}", ans);
}

fn count(x: i64) -> i64 {
    if x == 1 {
        1
    } else {
        1 + 2 * count(x / 2)
    }
}


Measured memory_bytes: 4352
x,y = map(int,input().split())
mod = 10**9 + 7

def getComb(a,b,mod):
  if b > a:
    return 0
  if a - b > b :
    b = a - b
  comb = 1
  for i in range(b+1,a+1):
    comb = (comb * i) % mod
  d = 1
  for i in range(1,a-b+1):
    d = (d * i) % mod
  comb *= pow(d,mod-2,mod)
  return comb % mod

if x > 2*y or y > 2*x:
  print(0)
  exit()
if (x+y)%3 != 0:
  print(0)
  exit()
times = (x+y)//3
tmp = abs(x-y)
xtimes = (times - tmp) //2
ans = getComb(times,xtimes,mod)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod;
int po(int a,int b){
    int res=1;
    while(b!=0){
        if(b&1){
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b/=2;
    }
    return res;
}
int inv(int a){
    return po(a,mod-2);
}
int32_t main(){
    int a,b,k;
  cin>>a>>b>>k;
  int t=min(a,k);
  a-=t; k-=t;
  t=min(b,k);
  b-=t;
  k-=t;
  cout<<a<<" "<<b;
  
    return 0;
}

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

const int M = 1000000007;

// min
class minsegtree {
    const int ex = M;
    int n, s, t;
    vector<int> tr;
    int q(int k, int l, int r) {
        return r <= s || t <= l ? ex : s <= l && r <= t ? tr[k]
            : min(q(k << 1 | 1, l, l + r >> 1), q(k + 1 << 1, l + r >> 1, r));
    }
public:
    minsegtree() {}
    minsegtree(int m) {
        n = 1;
        while (n < m) n <<= 1;
        tr.clear();
        tr.resize((n << 1) - 1, ex);
    }
    void update(int j, const int x) {
        int i = j + n - 1;
        tr[i] = x;
        while (i > 0) {
            i = i - 1 >> 1;
            tr[i] = min(tr[i << 1 | 1], tr[i + 1 << 1]);
        }
    }
    int run(int _s, int _t) {
        s = _s;
        t = _t;
        return q(0, 0, n);
    }
};

// sum
class sumsegtree {
    const int ex = 0;
    int n, s, t;
    vector<long long> tr;
    long long q(int k, int l, int r) {
        return r <= s || t <= l ? ex : s <= l && r <= t ? tr[k]
            : q(k << 1 | 1, l, l + r >> 1) + q(k + 1 << 1, l + r >> 1, r);
    }
public:
    sumsegtree() {}
    sumsegtree(int m) {
        n = 1;
        while (n < m) n <<= 1;
        tr.clear();
        tr.resize((n << 1) - 1, ex);
    }
    void update(int j, const long long x) {
        int i = j + n - 1;
        tr[i] = x;
        while (i > 0) {
            i = i - 1 >> 1;
            tr[i] = tr[i << 1 | 1] + tr[i + 1 << 1];
        }
    }
    long long run(int _s, int _t) {
        s = _s;
        t = _t;
        return q(0, 0, n);
    }
};

long long gett(const vector<int>& x) {
    sumsegtree sg(x.size());
    long long ans = 0;
    for (int i = 0; i < x.size(); ++i) {
        ans += i - sg.run(0, x[i]);
        sg.update(x[i], sg.run(x[i], x[i] + 1) + 1);
    }
    return ans;
}


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    vector<int> idxs(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        --x[i];
        idxs[x[i]] = i;
    }
    sumsegtree sumsg(n);
    minsegtree minsg(n);
    for (int i = 0; i < n; ++i) {
        sumsg.update(i, 1);
        minsg.update(i, x[i]);
    }
    long long t = gett(x) - k;
    vector<int> ans;
    for (int i = 0; i < n && t > 0; ++i) {
        int ok = 1, ng = n;
        if (sumsg.run(0, n) - 1 <= t)
            ok = n;
        while (ok < ng - 1) {
            int m = (ok + ng) / 2;
            if (sumsg.run(0, m) - 1 <= t)
                ok = m;
            else
                ng = m;
        }
        int mi = minsg.run(0, ok);
        if (mi == M) continue;
        int idx = idxs[mi];
        ans.push_back(mi);
        minsg.update(idx, M);
        sumsg.update(idx, 0);
        x[idx] = M;
        t -= sumsg.run(0, idx);
    }
    for (int i = 0; i < n; ++i)
        if (x[i] != M)
            ans.push_back(x[i]);

    for (int i = 0; i < n; ++i)
        cout << ans[i] + 1 << "\n";

    return 0;
}



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

int main(){
  
  int N,A;
  
  cin >> N >> A;
  
  if(N % 500 <= A){
  
    cout << "Yes" << endl;
  
  }else{
  
    cout << "No" << endl;
    
  }
  
  return 0;

}

Measured memory_bytes: 256
import numpy as np
n,p = map(int, input().split())
alist = map(int, input().split())
x = np.array([[2,0],[0,2]])
y = np.array([[1,1],[1,1]])
ans = np.array([1,0])
for a in alist:
  if a%2 == 0:
    ans = np.dot(x,ans)
  if a%2 == 1:
    ans = np.dot(y,ans)
print(ans[p])

Measured memory_bytes: 12600
#include <iostream>
#include <functional>
#include <queue>

#define INF 1000000000

using namespace std;
class Edge {
public:
    Edge(){};
    Edge(int s, int t, int w) : s {s}, t {t}, w {w} {};
    int s;
    int t;
    int w;
};

class Graph {
public:
    Graph(int v, vector<Edge> es) : n {v}, vs {vector<vector<Edge>>(v)} {
        for(auto e : es){
            vs[e.s].push_back(e);
            vs[e.t].push_back(e);
        }
    };
    vector<int> dijkstra(int st){
        auto ds = vector<int>(n, INF);
        auto que = priority_queue<Edge, vector<Edge>, function<bool(Edge, Edge)>>([](Edge a, Edge b){
                                                                                    return a.w > b.w;
                                                                                  }, vector<Edge>());
        que.push(Edge(st, st, 0));
        while(que.size()){
            Edge e = que.top();
            que.pop();
            if(ds[e.t] == INF){
                ds[e.t] = e.w;
                for(auto ne : vs[e.t]){
                    que.push(Edge(ne.s, ne.t, ne.w + ds[e.t]));
                }
            }
        }
        return ds;
    };
private:
    int n;
    vector<vector<Edge>> vs;
};
int main(){
    ios_base::sync_with_stdio(false);
    int v, e, r;
    cin >> v >> e >> r;
    auto es = vector<Edge>();
    int s, t, w;
    for(int i = 0; i < e; ++i){
        cin >> s >> t >> w;
        es.push_back(Edge(s, t, w));
    }
    auto gs = Graph(v, es);
    auto ds = gs.dijkstra(r);
    for(auto d : ds){
        if(d == INF){
            cout << "INF" << endl;
        } else {
            cout << d << endl;
        }
    }
}

Measured memory_bytes: 40300
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll s,w;
cin>>s>>w;
if(w>=s)
{
    cout<<"unsafe"<<endl;
}else
{
    cout<<"safe"<<endl;
}
return 0;
}


Measured memory_bytes: 3688
using System;

public class Test
{
	static public void Main( )
	{
		while( true ) {
			string[] str = Console.ReadLine().Split( ' ' );
			if( "?" == str[1] ) break;
			
			int a = int.Parse( str[0] );
			int b = int.Parse( str[2] );
			int res = 0;
			switch( str[1] ) {
				case "+": res = a + b;
					break;
				case "-": res = a - b;
					break;
				case "*": res = a * b;
					break;
				case "/": res = a / b;
					break;
			}
			
			Console.WriteLine( "{0}" , res );
		}
	}
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    string s;
    cin >> s;

    int N = (int)s.size();
    if ((N%2 == 0) ^ (s.front() == s.back())) cout << "Second" << '\n';
    else cout << "First" << '\n';
}

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

    solve();

    return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;
  int x = A ;
  int sum = 0;
  int a, b, c, d, e;
  
  for(x = A ; x < B + 1; x++){
    a = x/10000;
    b = x/1000 - 10*a;
    c = x/100 - 100*a - 10*b;
    d = x/10 - 1000*a - 100*b - 10*c;
    e = x - 10000*a -1000*b - 100*c -10*d;
    if(a == e && b == d){
      sum += 1;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300 + 1;
int a, b, c, dp[N][N][N];
int calc(int i, int j, int k) {
	if(i == j && j == k) return 0;
	if(i >= N || j >= N || k >= N) return 1e9;
	int &ret = dp[i][j][k];
	if(ret != -1) return ret;
	ret = 1+calc(i+2, j, k);
	ret = min(ret, 1+calc(i, j+2, k));
	ret = min(ret, 1+calc(i, j, k+2));
	ret = min(ret, 1+calc(i, j+1, k+1));
	ret = min(ret, 1+calc(i+1, j, k+1));
	ret = min(ret, 1+calc(i+1, j+1, k));
	return ret;
}
int main() {
	cin >> a >> b >> c;
	memset(dp, -1, sizeof dp);
	cout << calc(a, b, c) << endl;	
	return 0;
}

Measured memory_bytes: 106752
#include <stdio.h>
#include <string.h>

int main(void)
{
	char a[8];
	char s[101];
	char c[8];
	
	scanf("%s %s %s", a, s, c);
	printf("%c%c%c", a[0], s[0], c[0]);
	
	return 0;
}

Measured memory_bytes: 128
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    bool endFlag=false;
    while(!endFlag){
        string str;
        for(int i=0;i<3;i++){
            cin>>str;
            if(str=="0"){
                endFlag=true;
                break;
            }
            int a,b;a=b=0;
            for(int i=1;i<str.length();i++){
                if(str[i]=='A')a++;
                else b++;
            }
            if(a>b)a++;
            else b++;
            cout<<a<<" "<<b<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int n;
    int q;
    scanf("%d %d", &n, &q);

    queue<pair<string, int>> qu;
    for (int i = 0; i < n; ++i) {
        char c[100];
        int n;
        scanf("%s %d", c, &n);
        qu.push(make_pair(string{c}, n));
    }

    vector<pair<string, int>> completed;
    int now = 0;
    while (!qu.empty()) {
        auto t = qu.front();
        qu.pop();
        auto remain = t.second - q;
        if (remain <= 0) {
            now += q + remain;
            completed.push_back(make_pair(t.first, now));
        }
        else {
            now += q;
            qu.push(make_pair(t.first, remain));
        }
    }
    for (auto&& i : completed) {
        printf("%s %d\n", i.first.c_str(), i.second);
    }
}

Measured memory_bytes: 6580
# 入力を読み込む
N = int(input())
A = input().split()
B = input().split()
C = input().split()
# print(N, A, B, C)
# 食べた順番にBを並べる
result = 0
for i in range(N):
#  print(A[i])
#  print(B[int(A[i])-1])
  result = result + int(B[int(A[i])-1])  
  # Cについて考える
  if (i != 0):
    if (int(A[i]) - int(A[i-1]) == 1):
      #print(A[i])
      result = result + int(C[int(A[i-1])-1])
print(result)


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

const int mod=1e9+7;
long dp[101][20][20][20];
#define DP(i, a, b, c) dp[i][a-'A'][b-'A'][c-'A']

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

    DP(0, 'T', 'T', 'T')=1;
    for(int i=0; i<n; ++i) {
#define rep(i) for(char i: "ACGT"s)
        rep(a) rep(b) rep(c) rep(d) {
            string t;
            t+=a; t+=b; t+=c; t+=d;
            bool ok=t.find("AGC")==t.npos;
            for(int j=0; ok and j<3; ++j) {
                swap(t[j], t[j+1]);
                ok=t.find("AGC")==t.npos;
                swap(t[j], t[j+1]);
            }
            if (ok) (DP(i+1, b, c, d)+=DP(i, a, b, c))%=mod;
        }
    }

    long res=0;
    rep(a) rep(b) rep(c) (res+=DP(n, a, b, c))%=mod;
    cout<<res<<endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> v(1e6,LINF);
std::vector<int> q(1e6);int Q;
int L=pw(2,18);
void update(int a,int b,int c,int k,int l,int r){
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b)v[k]=c;
  else{
    update(a,b,c,k*2+1,l,(l+r)/2);
    update(a,b,c,k*2+2,(l+r)/2,r);
  }
}
int ma(int a){
  int k=a+L-1;
  int res=v[k];
  while(k){
    k=(k-1)/2;
    res=min(res,v[k]);
  }
  return res;
}
void qw(int s,int t,int x){
  int l,r;
  //cout<<s<<" "<<t<<" "<<x<<"   ";
  if(q[Q-1]<s-x)return;
  //cout<<"A"<<endl;
  int ll=-1,rr=Q-1;
  while(rr-ll>1){
    int m=(ll+rr)/2;
    if(q[m]>=s-x)rr=m;
    else ll=m;
  }
  l=rr;
  if(q[0]>t-x-1)return;
  //cout<<"B"<<endl;
  ll=0,rr=Q;
  while(rr-ll>1){
    int m=(ll+rr)/2;
    if(q[m]<=t-x-1)ll=m;
    else rr=m;
  }
  r=ll;
  //cout<<r<<" "<<l<<endl;
  if(r<l)return;
  //cout<<"AA"<<endl;
  //cout<<l<<" "<<r<<" "<<x<<endl;
  update(l,r+1,x,0,0,L);
  return;
}
//main
signed main(){
  int N;cin>>N>>Q;
  typedef pair<int,int> P;
  typedef pair<int,P> PP;
  std::vector<PP> a(N);
  for(int i=0;i<N;i++){
    int s,t,x;cin>>s>>t>>x;
    a[i]=PP(x,P(s,t));
  }
  sort(a.rbegin(),a.rend());
  for(int i=0;i<Q;i++)cin>>q[i];
  for(int i=0;i<N;i++){
    int s,t,x;x=a[i].first;
    s=a[i].second.first;
    t=a[i].second.second;
    qw(s,t,x);
  }
  for(int i=0;i<Q;i++){
    if(ma(i)==LINF)cout<<-1<<endl;
    else cout<<ma(i)<<endl;
  }
}


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

int N, M;
vector<vector<int>> G(100100);
vector<int> dp(100100, -1);

int rec(int v) {
  if (dp[v] != -1) return dp[v];

  int res = 0;
  for (auto nv : G[v]) res = max(res, rec(nv) + 1);
  return dp[v] = res;
}

int main() {
  cin >> N >> M;
  // G.assign(N, vector<int>());

  int x, y;
  REP(i,M) {
    cin >> x >> y;
    G[x-1].push_back(y-1);
  }

  int res = 0;
  REP(i,N) res = max(res, rec(i));
  cout << res << endl;
}

Measured memory_bytes: 8192
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


# 各テストの余裕を小さい順に
margins = [[i, a - b] for i, (a, b) in enumerate(zip(A, B)) if (a - b) > 0]
margins.sort(key=lambda m: m[1])

# 調整済みA
X = A[:]

# 余裕が大きい方から使っていく
for i in range(N):
    while (A[i] < B[i]) and margins:
        cost = B[i] - A[i]
        mi, margin = margins[-1]

        if margin > cost:
            margins[-1][1] -= cost
            A[mi] -= cost
            A[i] += cost

        else:
            margins.pop()
            A[mi] -= margin
            A[i] += margin


ans = 0
for a, b, x in zip(A, B, X):
    if b - a > 0:
        print(-1)
        break

    if a != x:
        ans += 1
else:
    print(ans)


Measured memory_bytes: 21552
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(N)]
    count = 0

    for n in range(N):
        result = 0
        for m in range(M):
            result += B[m] * A[n][m]
        count += 1 if result + C > 0 else 0
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k; cin >> k;
    if(k%2==0||k%5==0){
        printf("-1\n");
    }
    else{
        ll res=0;
        for(ll i=1;i<=2e7;i++){
            res=(res*10+7)%k;
            if(res==0){
                cout << i << endl;
                return 0;
            }
        }
        printf("-1\n");
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> vec;
  for(int i=0; i<n-1; i++){
    int c, s, f;
    cin >> c >> s >> f;
    for(int j=0; j<vec.size(); j++){
      if(vec[j] <= s){
        vec[j] = s+c;
      }else{
        if((vec[j]-s) % f == 0){
          vec[j] = vec[j]+c;
        }else{
          vec[j] = vec[j]+f-((vec[j]-s)%f)+c;
        }
      }
    }
    vec.push_back(c+s);
  }
  for(int i=0; i<n-1; i++){
    cout << vec[i] << endl;
  }
  cout << 0 << endl;
  return 0;
}

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

const int N = 4005;
const int mod = 998244353;
int combi[N][N];

int add(int x,int y) {
   return (x+y)%mod;
}
int mul(int x,int y) {
   ll ret = (ll)x*y;
   ret%=mod;
   return ret;
}
int H(int n,int x) {
   return combi[n+x-1][x-1];
}
void solve() {
   for(int i=0;i<N;++i) {
      combi[i][0] = combi[i][i] = 1;
      for(int j = 1;j<i;++j) {
         combi[i][j] = add(combi[i-1][j],combi[i-1][j-1]);
      }
   }
   int n,k;
   scanf("%d%d",&k,&n);
   int ret = 0;
   for(int t = 2;t<=k*2;++t) {
      int sp = 0;
      for(int i=1;i<=k;++i) {
         int y = t - i;
         if(i<y && y<=k) {
            ++sp;
         }
      }
      int rem = k - sp*2;
      if(t%2==0) {
         --rem;
      }
      int R = H(n,rem);
      if(t%2==0) {
         R = add(R,H(n-1,rem));
      }
      int pp = 2;
      for(int i=1;i<=min(n,sp);++i) {
         int tmp = H(n-i,rem + i);
         tmp = mul(tmp, combi[sp][i]);
         tmp = mul(tmp,pp);
         R = add(R,tmp);
         if(t%2==0 && n-i-1>=0) {
            R = add(R, mul(pp,mul(combi[sp][i],H(n-i-1,rem+i)) ));
         }
         pp = mul(pp,2);
      }
      printf("%d\n", R);
   }
}

int main(){
   //freopen("input.txt","r",stdin);
   solve();
   return 0;
}

Measured memory_bytes: 61440
#![allow(unused)]

use std::cmp::{min, max};

macro_rules! dbg {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Scanner<'a, R> {
        Scanner { reader: reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n: usize = sc.get();
    let abcs: Vec<[i64; 3]> =
        (0..n).map(|_| [sc.get(), sc.get(), sc.get()]).collect();

    let mut dp = vec![[0, 0, 0]; n];
    dp[0] = abcs[0];
    for i in 1..n {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + abcs[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + abcs[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + abcs[i][2];
    }

    println!("{}", dp[n - 1].iter().max().unwrap());
}

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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int cards = r * 100 + g * 10 + b;
    
    if (cards % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 100010
vii G(N, vi());

int main() {
	int n, m, i, j;
	cin >> n >> m;
	vi a(m), b(m);
	for (i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	int q;
	cin >> q;
	vi v(q), d(q), c(q);
	vii dp(11, vi(n, -1));
	for (i = 0; i < q; i++) {
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
		dp[d[i]][v[i]] = i;
	}
	for (i = 10; i > 0; i--) {
		for (j = 0; j < n; j++) {
			if (dp[i][j] >= 0) {
				for (int k = 0; k < G[j].size(); k++) {
					if (dp[i - 1][G[j][k]] < dp[i][j]) {
						dp[i - 1][G[j][k]] = dp[i][j];
					}
				}
				if (dp[i - 1][j] < dp[i][j]) {
					dp[i - 1][j] = dp[i][j];
				}
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (dp[0][i] == -1) {
			cout << 0 << endl;
		}
		else {
			cout << c[dp[0][i]] << endl;
		}
	}
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  if(n==1&&m==1)cout<<1<<endl;
  else if(n==1||m==1)cout<<max(m-2,n-2)<<endl;
  else cout<<(n-2)*(m-2)<<endl;
  return 0;
  }


Measured memory_bytes: 256
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> P;
#define X real()
#define Y imag()
ld restant(P p){return abs(p);}
//polar(x,y) mag=l,arg=y
//typedef unordered_set<ll> usll;
//typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll> > vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
//typedef unordered_multiset<int> umsi;
//typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<double,double> > vpd;
typedef pair<double,double> pd;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 1000000000000000001
#define ninf -1000000000000000001
#define ima INT_MAX
#define imi INT_MIN
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
#define all(x) x.be(),x.en()
#define eps 1e-9
const ld pii=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}



int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{	
int n;
cin>>n;
string s;
cin>>s;

si pro[26];
for(int i=0;i<n;i++)
pro[int(s[i])-97].insert(i);


int q;
cin>>q;
while(q--)
{
int x;
cin>>x;
if(x==1)
{
	int id;
	char c;
	cin>>id>>c;
	id--;
	if(s[id]!=c)
	{
	pro[s[id]-'a'].erase(id);
	s[id]=c;
	pro[c-'a'].insert(id);	
	}
	
}

else
{
	int ql,qr;
	cin>>ql>>qr;
	ql--;
	qr--;
	int ans=0;
	for(int i=0;i<26;i++)
	{
	if(pro[i].lower_bound(ql)!=pro[i].upper_bound(qr))
	ans++;
	}
	cout<<ans<<"\n";
}		
}


}return 0;}


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

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

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

int main() {
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  long long aa = 1LL;
  for (int i = 0; i < T.size(); i++) {
    aa = lcm(aa, T.at(i));
  }
  cout << aa << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n;
    vector<long long> count(100000, 0);
    
    cin >> n;
    count[0]++;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        count[temp]++;
    }

    for(int i = (n + 1) % 2; i < n; i+=2){
        if(count[i] != 2){
            cout << 0 << endl;
            return 0;
        }
    }
    long long output = 1;
    for(int i = 0; i < n / 2; i++)
        output = (output * 2) % MOD;
    cout << output << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc083/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    unsigned long long x, y;
    ll ans = 1;//xは必ず入る
    cin >> x >> y;
    while(1){
        x *= 2;
        if(x > y) break;
        ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
long x[1000],y[1000],z[1000],memo[1000],cnt,ans=0;
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>z[i];
	for(int a=-1;a<2;a+=2){
		for(int b=-1;b<2;b+=2){
			for(int c=-1;c<2;c+=2){
				for(int i=0;i<n;i++)memo[i]=(x[i]*a)+(y[i]*b)+(z[i]*c);
				sort(memo,memo+n);
				reverse(memo,memo+n);
				cnt=0;
				for(int i=0;i<m;i++)cnt+=memo[i];
				ans=max(ans,cnt);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
std::vector<long> l;
long ans;

int main(){
    scanf("%ld", &n);
    for(int i = 0; i < n; i++){
        long a;
        std::cin >> a;
        l.push_back(a);
    }
    std::sort(l.begin(), l.end());
    for(long i = 0; i < n; i++){
        for(long j = i+1; j < n; j++){
            auto it = std::lower_bound(l.begin(), l.end(), l[i] + l[j]);
            //printf("  %ld %ld %ld\n", i, j, it - l.begin());
            ans += std::max(0l, it - l.begin() - j - 1);
        }
    }
    printf("%ld\n", ans);
}


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

int main(){
  int N; string X;
  vector<string> s(60);
  vector<int> t(60);

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

  int x;
  for(int i=0; i<N; i++){
    if(s[i] == X) x = i;
  }

  int total = 0;
  for(int i=x+1; i<N; i++) total += t[i];
  
  cout << total <<endl;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

M = list(input())

S = [int(s) for s in M]
L = [0, 1] #生成する数字
num = 3 #生成するビット数
bit_list = list(product(["+", "-"], repeat=num))

tmp = 0
for b in bit_list:
    ans = 0
    # print(b)
    for i, o in enumerate(b):
        # print("I", o)
        if o == "+":
            if i == 0:
                ans = S[i] + S[i+1]
            else:
                ans += S[i+1]
        else:
            if i == 0:
                ans = S[i] - S[i+1]
            else:
                ans -= S[i+1]
    # print(ans)
    if ans == 7:
        tmp = b
        break
ans = ""
for i, c in enumerate(tmp):
    ans += M[i]
    ans += c
ans += M[-1] + "=7"
print(ans)



Measured memory_bytes: 3948
def sort_hills(lists):
    lists.sort()
    lists.reverse()
    return lists

x1=input()
x2=input()
x3=input()
x4=input()
x5=input()
x6=input()
x7=input()
x8=input()
x9=input()
x10=input()

listA=[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]
listA=sort_hills(listA)
print listA[0]
print listA[1]
print listA[2]

Measured memory_bytes: 4236
#include<cstdio> 
#include<iostream> 
#include<algorithm> 
using namespace std; 
int a[207]; 
int main() { 
	int ans = 0; 
	int n; 
	cin >> n; 
	for(int i = 1;i <= n << 1;++ i) 
		cin >> a[i]; 
	std::sort(a + 1,a + 2 * n + 1); 
	for(int i = 2 * n;i >= 1;i -= 2) { 
		ans += a[i - 1]; 
	} 
	cout << ans << endl; 
	
} 

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

int main(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int ans;
	if(B < C || D < A) ans = 0;
	else if(A <= C) ans = min(B, D) - C;
	else ans = min(B, D) - A;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int K = sc.nextInt();
		sc.close();

		Queue<String> queue = new PriorityQueue<String>();

		for(int i = 0 ; i < K; i++){
			for(int j = 0 ; j < s.length() ;j++){
				if(j >= s.length()-i){
					break;
				}
				else{
				queue.add(s.substring(j,j+i+1));
				}
			}
		}

		String[] S = new String[s.length() * K];
		for(int i = 0 ; i < S.length ; i++){
			S[i] = queue.poll();
		}


		int count = 1;
		for(int i = 0 ; i < S.length-1 ; i++){
			if(!S[i].equals(S[i+1])){
				count++;
			}
			if(count == K){
				System.out.println(S[i+1]);
				break;
			}
		}
		if(s.length() == 1){
			System.out.println(s);
		}

	}

}

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

suma = sum(a)
sumb = sum(b)
sousa = sumb-suma

import math
plus1=0
plus2=0
for i in range(n):
    if a[i] < b[i]:
        plus2+=math.ceil((b[i]-a[i])/2)
    elif a[i] > b[i]:
        plus1+=a[i]-b[i]

if plus1<=sousa and plus2<=sousa:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 40944
#include <bits/stdc++.h>
// #include <chrono>
// #include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846
 
ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}
 
int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}

int ceil(int a,int b){
	if(a%b == 0)return a/b;
	return a/b+1;
}


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
    // int t;
    //  cin >> t;
 
 //     while(t--){

 // }

int a,b,c,d;
cin >> a >> b >> c >> d;
int p = a*c;
int q = a*d;
int r = b*d;
int s = b*c;

cout << max(p,max(q,max(r,s))) << endl;


return 0;
	
	}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
		String S = sc.next();
        //整数の初期値０
		int num = 0;
        //１～４文字目を取り出す
		char[] ch = new char[4];
		for(int i=0; i<4; i++){
	 		ch[i] = S.charAt(i);
        }
        for(int i=0; i<4; i++){
          if(ch[i] == '+'){
        	num++;
          } else {
        	num--;
          }
        }
		// 出力
		System.out.println(num);
	}
}

Measured memory_bytes: 23764
n=int(input())
p=list(map(int,input().split()))
a=[i for i in range(1,n+1)]
a.sort()
tmp=0
for i in range(n):
    if a[i]!=p[i]:
        tmp+=1
if tmp==0 or tmp==2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		sc.close();
		int res = N % 500;
		if(res > A) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21844
/*input
z
*/

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

int main() {
  char c;
  cin >> c;
  if ('A' <= c && c <= 'Z') cout << 'A' << endl;
  else cout << 'a' << endl;
}

Measured memory_bytes: 3604
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<lint> a(26, 0);
    REP(i, 4){
        a[s[i] - 'A']++;
    }
    lint two = 0;
    REP(i, 26){
        //cout << a[i] << endl;
        if(a[i] == 2){
            two++;
        }
    }
    if(two == 2){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  rep(i,10000){
    int X=i*(i+1)/2;
    if(N<=X){
      rep(j,i){
        if(j+1==X-N) continue;
        else cout<<j+1<<endl;
      }
      break;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n, m, c, i, j;
  	int a[21][21], b[21];
  	int ans = 0;
  	int add = 0;
  
  	scanf("%d %d %d", &n, &m, &c);
  
  	for(i=0; i<m; i++){
    	scanf("%d", &b[i]);
    }
  
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d", &a[i][j]);
        }
    }
  
 	for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            add += a[i][j] * b[j];
        }
     	if(add+c > 0){
        	ans++;
        }
      	add = 0;
    }
  	printf("%d", ans);
  	return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;
	auto convert = [](string a) -> string {
		string res = a;
		auto b = vector<int>('z' + 1);
		int p = 'a';
		for(auto i = 0; i < (int)a.size(); ++i){
			char c = a[i];
			if(b[c] == 0) b[c] = p++;
			res[i] = (char)b[c];
		}
		return res;
	};
	cout << (convert(s) == convert(t) ? "Yes" : "No") << endl;
	return 0;
}

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

int main()
{
    int c[3][3];
    rep(i, 0, 3)
    rep(j, 0, 3)
        cin >> c[i][j];
    
    int b1 = c[0][0];
    int b2 = c[0][1];
    int b3 = c[0][2];
    int a1 = 0;
    int a2 = c[1][0] - b1;
    int a3 = c[2][0] - b1;
    
    bool ans = true;
    ans &= c[1][1] == a2 + b2;
    ans &= c[1][2] == a2 + b3;
    ans &= c[2][1] == a3 + b2;
    ans &= c[2][2] == a3 + b3;
    
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256