akhauriyash/Code-Regression huggingface dataset:
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

	final long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		for (int h = 1; h <= 3500; ++h) {
			for (int w = 1; w <= 3500; ++w) {
				if ( 4 * h * w - N * w - N * h > 0&&N * h * w % (4 * h * w - N * w - N * h) == 0 ) {
					long n = N * h * w / (4 * h * w - N * w - N * h);
					System.out.println(h + " " + w + " " + n);
					return;
				}
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


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

int main()
{
	int A, B;
	cin >> A >> B;
	if (A == B)
		cout << "Draw\n";
	else if (A == 1)
		cout << "Alice\n";
	else if (B == 1)
		cout << "Bob\n";
	else if (A > B)
		cout << "Alice\n";
	else if (A < B)
		cout << "Bob\n";

}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

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

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	int n = s.length();
	int a, b, c, d;
	a = 0; b = 0; c = 0; d = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'N') a++;
		else if(s[i] == 'S') b++;
		else if(s[i] == 'W') c++;
		else d++;
	}
	if((a>0&&b==0)||(a==0&&b>0)) cout<<"No";
	else if((c>0&&d==0)||(d>0&&c==0)) cout << "No";
	else cout << "Yes";
}


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

int main(){
  int n;
  cin >> n;
  while(n!=0){

  int a,b,c;
  int dc[10][10];
  int count=-1;
  int m=0;
  int s=0;
  int num=0;



	  
  for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
		if(i==j)
			dc[i][j]=0;
		else
			dc[i][j]=1000;
	}
  }

  
  for(int i=0;i<n;i++){
	cin >> a >> b >> c;
	dc[a][b]=c;
	dc[b][a]=c;
	if(count<a)
		count=a;
	if(count<b)
		count=b;
  }

  count=count+1;

  for(int l=0;l<count;l++){
	for(int i=0;i<count;i++){
		for(int j=0;j<count;j++){
			if(dc[i][l]==1000||dc[l][j]==1000)
				continue;
			else if(dc[i][j]==1000)
				dc[i][j]=dc[i][l]+dc[l][j];
			else if(dc[i][j]>dc[i][l]+dc[l][j])
				dc[i][j]=dc[i][l]+dc[l][j];
		}
	}
  }

  m=0;
  s=0;

  for(int i=0;i<count;i++)
	  s+=dc[0][i];

  for(int i=1;i<count;i++){
	  num=0;
	  for(int j=0;j<count;j++){
		  num+=dc[i][j];
	  }
	  if(num<s){
		m=i;
		s=num;
	  }
  }

  cout << m << ' ' << s << endl;

  cin >> n;
  count=-1;
  num=0;

  }

  return 0;
}


Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e5;
int f(int a, int k){
  if(a<k) return 0;
  int d = a/k;
  if(a%k==0) return d;
  a -= (a-d*k+d)/(d+1)*(d+1);
  return f(a, k);
}
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int ans = 0;
  FOR(_, 0, n){
    int a, x;
    cin >> a >> x;
    ans ^= f(a, x);
  }
  cout << (ans ? "Takahashi" : "Aoki") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;
typedef long long ll;

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

	ll N, temp;
	vector<ll> ARR;

	cin >> N;

	REP(i, N)
	{
		cin >> temp;
		ARR.pb(temp);
	}

	temp = 0;
	ll c_max = 0;

	REP(i, N - 1)
	{


		if (ARR[i] >= ARR[i + 1])
		{
			temp++;
		}
		else
		{
			temp = 0;
		}
		if (c_max < temp) c_max = temp;
	}

	cout << c_max << endl;

	return 0;
}

Measured memory_bytes: 1400
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<fixed<<setprecision(10)<<1.*w*h/2;
	if(w/2 == x && h/2 == y) cout<<" 1"<<endl;
	else cout<<" 0"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    bool found=false;
    for(int i=0; i<s.size(); ++i){
        string s2=s.substr(i, s.size()-i)+s.substr(0, i);
        if(t==s2){
            found=true;
            break;
        }
    }
    cout << (found ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
using VP = vector<P>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

string toN(string str) {
    rep(i, str.size()) {
        str[i] = str[i] - 'a';
    }
    return str;
}

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

    V cs(26), ct(26);
    rep(i, s.size()) cs[s[i]]++;
    rep(i, t.size()) ct[t[i]]++;
    sort(all(cs));
    sort(all(ct));

    bool ret = true;
    if (cs.size() != ct.size()) ret = false;
    rep(i, cs.size()) {
        if(cs[i] != ct[i]) ret = false;
    }
    
    if(ret) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 984
while True:
    x = input()
    list = x.split()
    list_i = [int(s) for s in list]
    [H, W] = list_i
    
    if H == 0 and W == 0:
        break
    for t in range(H):
        for y in range(W - 1):
            print("#", end="")
        print("#")
    print()


Measured memory_bytes: 7052
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  if(k<x/d){
    x -= k*d;
  }else{
    k -= x/d;
    x %= d;
    x = k&1 ? d-x : x;
  }
  cout << x << endl;
}


Measured memory_bytes: 3640
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

struct edge{
    ll x,y,c;
    edge(){}
    edge(ll a, ll b, ll cc){
        x = a; y  =b; c = cc;
    }
};

ll a,k,u;
vec<vec<pll>> l;
vec<edge> ee;

int main(){
    fast;
    cin>>a>>k>>u;
    l = vec<vec<pll>>(a, vec<pll>());
    for(int q=0; q<k; q++){
        ll x,y,c; cin>>x>>y>>c;
         x--; y--;
         c-=u;
         ee.pb(edge(x,y,c));
         l[x].pb({y,c});
    }
    ll inf = 1e18;
    vec<ll> d(a, -inf);
    d[0] = 0;
    ll fl = 1, o = -1;
    for(int g=0; g<a*2; g++){
        for(edge e : ee){
            d[e.y] = max(d[e.y], min(d[e.x]+e.c, inf));
        }
        if(g==a-1) o = d[a-1];
        else if(g>a-1) fl&=o==d[a-1];
    }
    if(fl) cout<<max(0LL, o);
    else cout<<-1;

}

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

int main(){
  string s;
  cin >> s;
  int a = s.size() - 1,z = 0;
  for(int i = 0; i < s.size();i++){
    if(s.at(i) == 'A' && i < a){
      a = i;
    }else if(s.at(i) == 'Z' && i > z){
      z = i;
    }
  }
  cout << ( z - a + 1 ) << endl;
}

Measured memory_bytes: 640
raw_input()
t=raw_input()
hayIzqN=[]
hayDerB=[]
N=0
B=0
for i in t:
	if i=="#":
		N+=1
	else:
		B+=1
cant=2000000
blan=0 
hay_n=False
conv=0
b=0
n=0
for i in xrange(len(t)):
	if t[i]=="#":
		hay_n=True
		cant=min(cant, B-b+conv)
		conv+=1
	else:
		b+=1
cant=min(cant, N)
print cant


Measured memory_bytes: 2948
x,y=map(int,input().split())
if x>=0 and y>=x:
  print(y-x)
elif x>=0 and x>=abs(y):
  print(min(1+y+x,x-y+2))
elif x>=0 and abs(y)>x:
  print(abs(y)-x+1)
elif x<0 and y>=abs(x):
  print(y-abs(x)+1)
elif x<0 and abs(x)>=abs(y):
  print(min(y+abs(x),abs(x)-y+1))
elif x<0 and y<x:
  print(min(abs(y)-abs(x)+2,abs(y)+abs(x)+1))
  

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

struct Sweet{ int i, p, q, r; };

int main(){
    int n;
    while(1){
        vector<Sweet> sweets;
        cin >> n;
        if(!n) break;
        for(int i = 0;i < n;i++){
            Sweet sw;
            cin >> sw.i >> sw.p >> sw.q >> sw.r;
            sweets.push_back(sw);
        }
        
        int P, Q, R, C;
        cin >> P >> Q >> R >> C;
        
        int count = 0;
        for(int i = 0;i < sweets.size();i++){
            Sweet s = sweets[i];
            int c = s.p * 4 + s.q * 9 + s.r * 4;
            if(s.p <= P && s.q <= Q && s.r <= R && c <= C){
                cout << s.i << endl;
                count++;
            }
        }
        if(count == 0) cout << "NA" << endl;
    }
    
    return 0;
}

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

int main()
{
	int i;
	char word;
	int num = 0;
	int cnt[26] = {};
	
	while(cin >> word)
	{
		if(isalpha(word) != 0)
		{
			word = tolower(word);
			num = word - 'a';
			cnt[num]++;
		}
	}
	for(i = 0; i < 26; i++)
	{
		cout << char(i + 'a') << " : " << cnt[i] << endl;
	}
}



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

int main() {
  string s;
  cin >> s;
  bool N=false,S=false,W=false,E=false;
  for(int i=0;i<s.length();i++){
    if(s[i]=='N')N=true;
    if(s[i]=='S')S=true;
    if(s[i]=='W')W=true;
    if(s[i]=='E')E=true;
  }
  bool ans=true;
  if(N && !S)ans=false;
  if(!N && S)ans=false;
  if(W && !E)ans=false;
  if(!W && E)ans=false;
  if(ans)cout <<"Yes";
  else cout << "No";
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;


double lowerSum[200001];
double upperSum[200001];

int main()
{
	int n, k;

	cin >> n >> k;

	long ans = 0;
	lowerSum[0] = 0;
	upperSum[0] = 0;

	for (int i = 0; i <= n; ++i)
	{
		lowerSum[i + 1] = lowerSum[i] + i;
		upperSum[i + 1] = upperSum[i] + (n - i);
	}



	for (int i = k; i <= n; ++i)
	{
		double t = upperSum[i] - lowerSum[i] + 1;
		ans = (double(ans) + t) - floor( (double(ans) + t) / 1000000007 ) * 1000000007;
	}
	ans = (ans + 1) % 1000000007;

	cout << ans << endl;

	return 0;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long N, M;
  cin >> N >> M;

  cout << min(N, M/2) + max((M-(N*2))/4, 0LL) << endl;

  return 0;
}


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

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

    int a = -1;
    int b = -1;
    int c = -1;

    bool flag = false;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n-i; j++){
            int total = (n - i - j) * 10000 + i * 5000 + j * 1000;
            if(total == y){
                a = n - i - j;
                b = i;
                c = j;
                flag = true;
                break;
            }
        }
        if(flag == true) break;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
map<int, int> cnt;
int main() {
	int N;
	cin >> N;
	rep(i, N) {
		int D;
		cin >> D;
		cnt[D]++;
	}
	int M;
	cin >> M;
	bool OK = 1;
	rep(i, M) {
		int T;
		cin >> T;
		if (cnt[T] > 0) cnt[T]--;
		else {
			OK = 0;
			break;
		}
	}
	if (OK) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 9600
a, b, c, d = [int(_) for _ in input().split()]


#[1,x]のうちCで割り切れる
def C(x):
    return x // c


#Dで割り切れる
def D(x):
    return x // d


gcd = lambda x, y: gcd(y, x % y) if x % y else y


#CでもDでも割り切れる
def CD(x):
    return x // (c * d // gcd(c, d))


#CまたはDで割り切れる
def CorD(x):
    return C(x) + D(x) - CD(x)


#CでもDでも割り切れない
def CnorD(x):
    return x - CorD(x)


print(CnorD(b) - CnorD(a - 1))


Measured memory_bytes: 3060
h, w = map(int, input().split())

mp = []
for _ in range(h):
  lst = list(map(int, input().split()))
  cum = []
  acc = 0
  for i in lst:
    if not i:
      acc += 1
    else:
      acc = 0
    cum.append(acc)
  mp.append(cum)
mp.append([-1] * w)
ans = 0

#print(*mp, sep="\n")
for i in range(w - 1, -1, -1):
  stack = []
#  print(ans)
  for j in range(h + 1):
#    print(stack)
    score = mp[j][i]
    if not stack:
      stack.append((score, j))
    else:
      last_score, last_ind = stack[-1][0], stack[-1][1]
      if score > last_score:
        stack.append((score, j))
      elif score == last_score:
        continue
      else:
        while stack and stack[-1][0] > score:
          last_score, last_ind = stack.pop()
          ans = max(ans, last_score * (j - last_ind))
        if not stack:
          stack.append((score, last_ind))
        elif stack[-1][0] == score:
          pass
        else:
          stack.append((score, last_ind))

print(ans)


Measured memory_bytes: 52588
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 2e5 + 1;
ll dp[N];
vector<ll> adj[N];
void dfs(ll a, ll par){
    for(auto u : adj[a]){
        if(u == par){
            continue;
        }
        dp[u] += dp[a];
        dfs(u, a);
    }
} 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n, q;
        cin >> n >> q;
        for(i = 0; i < n - 1; i++){
            ll a ,b;
            cin >> a >> b;
            adj[a].pb(b);
            adj[b].pb(a);
        }
        while(q--){
            ll a, b;
            cin >> a >> b;
            dp[a] += b;
        }
        dfs(1, -1);
        for(i = 1; i <= n; i++){
            cout << dp[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 25540
from collections import deque
import sys
readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
def bfs(s):
    dist = [None]*N
    que = deque([s])
    dist[s] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] is not None:
                continue
            dist[w] = d + 1
            que.append(w)
    d = max(dist)
    return dist.index(d), d
u, _ = bfs(0)
v, d = bfs(u)
print("Second" if d % 3 == 1 else "First")

Measured memory_bytes: 47512
Module Hitachi2020A

    Sub Main()
        Dim S As String
        Dim i As Integer

        S = Console.ReadLine()

        For i = 0 To S.Length - 1
            If i = S.Length - 1 Then
                Console.Write("No")
                Exit Sub
            End If
            If S.Substring(i, 2) = "hi" Then
                i = i + 1
            Else
                Console.Write("No")
                Exit Sub
            End If
            If i = S.Length Then
                Exit For
            End If
        Next
        Console.Write("Yes")
    End Sub

End Module


Measured memory_bytes: 20432
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_A
#????????????

def insert(root, insert_node):
    focus_node = root
    parent = None
    while not focus_node == None:
        parent = focus_node
        if focus_node["data"]  > insert_node["data"]:
            focus_node = focus_node["left"]
        else:
            focus_node = focus_node["right"]

    if parent["data"] > insert_node["data"]:
        parent["left"] = insert_node
    else:
        parent["right"] = insert_node

def get_preorder(node):
    if node == None:
        return []
    r = []
    r.append(str(node["data"]))
    r.extend(get_preorder(node["left"]))
    r.extend(get_preorder(node["right"]))

    return r
    
def get_inorder(node):
    if node == None:
        return []
    r = []
    r.extend(get_inorder(node["left"]))
    r.append(str(node["data"]))
    r.extend(get_inorder(node["right"]))

    return r

def find_tree(root, target):
    focus_node = root

    while not focus_node == None:
        if focus_node["data"] == target:
            print("yes")
            return
        elif focus_node["data"] < target:
            focus_node = focus_node["right"]
        else:
            focus_node = focus_node["left"]
    
    print("no")
    
def print_tree(root):
    print(" " + " ".join(get_inorder(root)))
    print(" " + " ".join(get_preorder(root)))
    
def main():
    
    n_line = int(input())
    input_list = [input() for i in range(n_line)]
    root = {"left":None, "right": None, "data":int(input_list[0].split()[1])}

    for line in input_list[1:]:
        if line == "print":
            print_tree(root)
        else:
            split_line = line.split()
            if split_line[0] == "insert":
                node = {"left":None, "right": None, "data":int(split_line[1])}
                insert(root, node)
            elif split_line[0] == "find":
                find_tree(root, int(split_line[1]))
        
        

if __name__ == "__main__":
    main()

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

typedef long long ll;

int main(){
    int n; cin >> n;
    int t[n], sum=0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
        sum+=t[i];
    }
    int m; cin >> m;
    int p[m], x[m];
    for(int i=0; i<m; i++){
        cin >> p[i] >> x[i];
    }
    for(int i = 0; i < m; i++)
    {
        cout << sum-(t[p[i]-1]-x[i]) << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

f, t = 0, 0
for a in A:
    if a % 4 == 0:
        f += 1
    elif a % 2 == 0:
        t += 1

if N - f - t <= f + (t == 0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
let lines = input.split("\n");
if (Number(lines[0]) === 52) {
  return false;
}

let myCards = {
  'S':[],
  'H':[],
  'C':[],
  'D':[]
};
let result = '';

for (var i = 1; i < lines.length; i++) {
  let mark = lines[i].substr(0,1);
    let target;
    //myCards[mark].push は run でエラー
    switch (mark) {
    case 'S':
      myCards.S.push(Number(lines[i].substr(1)));
      break;
    case 'H':
      myCards.H.push(Number(lines[i].substr(1)));
      break;
    case 'C':
      myCards.C.push(Number(lines[i].substr(1)));
      break;
    case 'D':
      myCards.D.push(Number(lines[i].substr(1)));
      break;
    default:
    break;
  }
}

for (var mark in myCards) {
 for (var count = 1; count <= 13; count++) {
   if (myCards[mark].indexOf(count) == -1){
  // 存在しない
  result += mark + ' ' + count + '\n';
  }
 }
}

console.log(result.slice( 0, -1));


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

int main() {
    string S, T;
    int count = 0;
    cin >> S >> T;

    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) != T.at(i)) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3832
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int d,t,s;
    cin >> d >> t >> s;
    if(s*t >= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

lli body(lli a, lli b){
	return (a-b)*(a-b);
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	lli cnt=0, a, b;
	cin >> n;
	vector<int> P(n);
	vector<int> Q(n);
	vector<int> X(n,1);

	rep(i,n) cin >> P[i];
	//rep(i,n) cout << P[i]<< " ";
	rep(i,n) cin >> Q[i];
	//rep(i,n) cout << Q[i] << " ";
	iota(all(X), 1);

	do{
		if(X == P) a = cnt;
		if(X == Q) b = cnt;
		++cnt;
	}while(next_permutation(all(X)));
	cout << abs(a-b) << endl;
 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

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

    queue<int> q;
    vi dist(n, INF);
    
    //カウントする時番号気を付けて
    vi count(n, 0);

    auto update = [&](int i, int z){
        if(dist[i]!=INF) return;
        dist[i] = z;
        q.push(i);
    };

    rep(i, n){
        dist = vi(n, INF);
        update(i, 0);

        while(!q.empty()){
            int j = q.front();
            q.pop();
            
            int rj, lj, yj;

            rj = j + 1;
            if(rj < n) update(rj, dist[j]+1);
            
            lj = j - 1;
            if(lj>=0) update(lj, dist[j]+1);

            if(j == x) update(y, dist[j]+1);
            if(j == y) update(x, dist[j]+1);
        }
        /*
        printf("\n\n%d\n:", i);
        rep(i, n){
            printf("%d ", dist[i]);
        }
        */

        rep(i, n){
            count[dist[i]]++;
        }
    }

    rrep(i, n-1){
        cout << count[i]/2 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())


def solve():
    if K == 0:
        return True
    if K % M == 0:
        return True
    if K % N == 0:
        return True

    for cr in range(N + 1):
        for cc in range(M + 1):
            count = cr * M + cc * N
            if cc > 0:
                count -= cc * cr
            if cr > 0:
                count -= cc * cr
            if count == K:
                return True
            # print(cr, cc, count)
    
    return False

if solve():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 39024
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int y, m, d;
        cin >> y >> m >> d;
        int count = 0;
        if (y%3==0) {
            count += 20 - d + 1;
            count += ((10 - m) / 2) * (20 + 20) + ((10 - m) % 2) * 20;
        } else {
            count += 19 - d + (m%2) + 1;
            count += ((10 - m) / 2) * (19 + 20) + ((10 - m) % 2) * 19;
        }
        count += ((999 - y) / 3) * (59*10) + ((999 - y) % 3 % 2) * (20*10);
        if ((999 - y) % 3 == 2) {
            count += 19*5 + 20*15;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            int ans = 0;
            for (int available = 1; available < B;)
            {
                ans++;
                available--;
                available += A;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
n=int(input())
c=[]
hc=0
for i in range(n):
  a=int(input())
  l,r=-1,hc
  while r-l!=1:
    t=(l+r)//2
    if c[t]<a:
      r=t
    else:
      l=t
  if r==hc:
    c.append(a)
    hc+=1
  else:
    c[r]=a
print(hc)

Measured memory_bytes: 75236
#include <iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(void){
    int N,T;
    int ans=99999;
    cin>>N>>T;
    vector<int> c(N);
    vector<int> t(N);
    for(int i=0;i<N;i++)
    {
        cin>>c[i]>>t[i];
    }
    
    for(int i=0;i<N;i++)
    {
        if(t[i]<=T)
        {
            ans=min(ans,c[i]);
        }
    }
    if(ans==99999)  cout<<"TLE";
    else    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

int n, m, x, y, z;
pair<pair<int,int> ,int> A[100000+2];
string ANS[100000+2];

int s = 1, cnt = 0;

string cal(int a){
	if (a != s){
		s = a;
		cnt = 1;
	} else ++cnt;
	string x = "", y = "";
	while (a){
		x += (a%10+'0');
		a/=10;
	}
	int temp = cnt;
	while (temp){
		y += (temp%10+'0');
		temp/=10;
	}
	reverse(x.begin(),x.end());
	reverse(y.begin(),y.end());
	while (x.size() != 6){
		x = "0" + x;
	}
	while (y.size() != 6){
		y = "0" + y;
	}
	return x + y;
}

void solve(){
	cin >> n >> m;
	for (int i=1; i<=m; ++i){
		cin >> A[i].fs.fs >> A[i].fs.sc;
		A[i].sc = i;
	}
	sort(A+1,A+m+1);
	for (int i=1; i<=m; ++i){
		ANS[A[i].sc] = cal(A[i].fs.fs);
	}
	for (int i=1; i<=m; ++i){
		cout << ANS[i] << '\n';
	}
}	

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

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;

int main(){
	char a[4];
	int f = 0;
	for(int i=0; i<4; i++) cin >> a[i];
	for(int i=0; i<3; i++){
		if(a[i] == a[i+1]) f = 1;
	}
	if(f) cout << "Bad" << endl;
	else cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 764
import math
ah,ast,bh,bst=[int(x) for x in input().split()]
if(bh<=ast):
    print("Yes")
else:
    count_tak=math.ceil(ah/bst)
    count_aok=math.ceil(bh/ast)
    if(count_aok<=count_tak):
        print("Yes")
    else:
        print("No")


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

using namespace std;

const int maxn = 2e5 + 10;
int n, a[maxn], d[maxn], ans;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		d[a[i]] = i;
	}
	int t = 1;
	for (int i = 2; i <= n; ++i)
		if (d[i] > d[i - 1])
			++t;
		else {
			ans = max(ans, t);
			t = 1;
		}
	ans = max(ans, t);
	ans = n - ans;
	cout << ans << '\n';
	return 0;
}


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

int main() {
   string s;
   cin >> s;
   if(s=="ABC")cout << "ARC" <<endl;
   if(s=="ARC")cout << "ABC" <<endl;
    return 0;
}

Measured memory_bytes: 3632
import math
N = int(input())
plist = [2]
for i in range(3, N + 1):
    for prime in plist:
        if i % prime == 0:
            break
    else:
        plist.append(i)
ans = 1
for prime in plist:
    s = 0
    for i in range(1, int(math.log(N, prime)) + 1):
        s += N // (prime ** i)
    ans = ans * (s + 1) % (10 ** 9 + 7)
print(ans)


Measured memory_bytes: 3060
def binary_search ss, t
  while ss
    len = ss.length
    break if len == 0
    i = len / 2
    if ss[i] == t
      return true
    elsif ss[i] < t
      ss = ss.slice((i+1)..(len-1))
    else
      if len == 1
        ss = []
      else
        ss = ss.slice(0..(i-1))
      end
    end
  end
  false
end

n = gets.chomp.to_i
ss = gets.chomp.split(' ').map(&:to_i)
q = gets.chomp.to_i
ts = gets.chomp.split(' ').map(&:to_i)

c = 0
ts.each do |t|
  c += 1 if binary_search ss, t
end
puts c


Measured memory_bytes: 18576
#include<string>
#include<iostream>

using namespace std;

int main(void) {

	string A, B, C;

	cin >> A >> B >> C;

	if (A[A.length() - 1] == B[0]) {
		if (B[B.length() - 1] == C[0]) {
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
	


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 998244353;
const double PI = 3.141592653589793238463;
const int MAXN = 1000030;

int main()
{
    FAST

   ll n;
   ld d;
   cin>>n>>d;
   vector<ld> v;
   for(int i=0;i<n;i++){
    ld a,b;
    cin>>a>>b;
    v.push_back(sqrt(a*a+b*b));
   }
   sort(v.begin(),v.end());
   auto pt=upper_bound(v.begin(),v.end(),d);
   if(pt==v.end()){
    cout<<n<<endl;
   }
   else{
    cout<<n-(v.end()-pt)<<endl;
   }

    return 0;
}


Measured memory_bytes: 7548
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N;
  string r = "";
  
  bool redu = false;
  N--;
  while (N >= 26) {
    char tm=('a' + (char)(N % 26));
    redu = true;
    r = tm + r;
    N /= 26;
    N--;
  }
    char tm=('a' + (char)(N % 26));

    r = tm + r;



  return r;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3628
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n;
string s;
unordered_set<string>SET;
unordered_map<string,ll>byk;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s;
        sort(s.begin(),s.end());
        SET.insert(s);
        byk[s]++;
    }
    ll ans=0;
    for(string isi:SET){
        ans+=(byk[isi]*(byk[isi]-1))/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 19400
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner (System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] c = new int[N];
		int[] t = new int [N];
		int p = 1001;
		for (int i = 0; i < N; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			if (t[i] <= T && c[i] < p) {
				p = c[i];
			}
		}
		if (p == 1001) {
			System.out.println("TLE");
		} else {
			System.out.println(p);
		}
	}
}

Measured memory_bytes: 22100
///HR_Bappy
//
///*******

#include<bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define maxx 1000000005
#define MOD 1000003
#define sf(n) scanf("%lld", &n);
#define sff(n,m) scanf("%lld %lld", &n, &m)
#define pf(n) printf("%lld\n", n)
#define pff(n,m) printf("%lld %lld\n", n, m)
#define mem(a) memset(a, 0, sizeof(a))
#define fr(i,n) for(ll i=0; i<n; i++)
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
#define pi 2*acos(0.0)
#define F first
#define S second
#define EPS 1e-9

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    vector<int>v;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        if(b)
            v.pb(b);
    }
    int c = 0;
    for(int i = 0 ; i < v.size(); i++){
        for(int j = i+1; j < v.size(); j++){
            c += v[i]*v[j];
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, R, P[300000], t[300000], s[300000];
map<int, int>mp;
vector<pair<int, int>>v;

int par(int x) {
	if (t[x] < 0)return x;
	return t[x] = par(t[x]);
}

void uni(int x, int y) {
	x = par(x);
	y = par(y);
	if (x == y)return;
	if (t[x] < t[y]) {
		t[x] += t[y];
		t[y] = x;
	}
	else {
		t[y] += t[x];
		t[x] = y;
	}
}


int main() {
	cin >> N >> R;
	memset(t, -1, sizeof t);
	for (int i = 0; i < N; ++i) {
		cin >> P[i];
		--P[i];
		uni(P[i], i);
	}
	for (int i = 0; i < N; ++i) {
		if (t[i] < 0) {
			++mp[-t[i]];
		}
	}
	for (pair<int, int>p : mp) {
		v.push_back(p);
	}
	R = min(R, N - R);
	vector<vector<bool>>DP(v.size() + 1, vector<bool>(R + 1));
	DP[0][0] = true;
	for (int i = 0; i < v.size(); ++i) {
		vector<int>u(R + 1, -1);
		for (int j = 0; j <= R; ++j) {
			if (DP[i][j]) {
				u[j] = v[i].second;
			}
		}
		for (int j = 0; j <= R; ++j) {
			if (u[j] != -1) {
				DP[i + 1][j] = true;
				if (j + v[i].first <= R) {
					u[j + v[i].first] = max(u[j + v[i].first], u[j] - 1);
				}
			}
		}
	}
	if (DP[v.size()][R]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 20028
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  string S;
  cin>>S;
  rep(i,S.size())if(S.at(i)=='?')S.at(i)='D';
  cout<<S<<endl;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int ans=0,i=1;
  while(1){
    if((y+z)*i>x-z){
      ans=i-1;
      break;
    }
    i++;
  }
  cout<<ans<<endl;
  return(0);
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;

#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll T[105];
ll gcd(ll a,ll b){
if(a<b) swap(a,b);
if(a%b==0) return b;
else return gcd(a%b,b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
ll ans;

int main(){

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

cin>>N;

rep(i,N) cin>>T[i];

if(N==1){
	cout<<T[0]<<endl; return 0;
}

ans=lcm(T[0],T[1]);
for(ll i=2; i<N; i++){
	ans=lcm(ans,T[i]);
}

cout<<ans<<endl;



}
	


Measured memory_bytes: 256
# D - Wizard in Maze
import sys
from collections import deque
from typing import List, Tuple


class WarpableMaze:
    __slots__ = ["height", "width", "start", "goal", "road", "wall", "grid"]

    def __init__(
        self,
        height: int,
        width: int,
        start: Tuple[int, int],
        goal: Tuple[int, int],
        grid: List[str],
        road: str = ".",
        wall: str = "#",
    ) -> None:
        # Values of start and goal must be 0-origin.
        self.height = height + 4
        self.width = width + 4
        self.start = self._flatten_coordinate(*start)
        self.goal = self._flatten_coordinate(*goal)
        self.road = road
        self.wall = wall
        self.grid = self._flatten_grid(grid)

    def _flatten_coordinate(self, h: int, w: int) -> int:
        return self.width * (h + 2) + w + 2

    def _flatten_grid(self, grid: List[str]) -> str:
        flat_grid = self.wall * self.width * 2
        for row in grid:
            flat_grid += self.wall * 2 + row + self.wall * 2
        flat_grid += self.wall * self.width * 2
        return flat_grid

    def bfs(self) -> int:
        w = self.width
        move = (-w, w, -1, 1)
        warp = [-2 * w - 2, -2 * w - 1, -2 * w, -2 * w + 1, -2 * w + 2]
        warp.extend([-w - 2, -w - 1, -w + 1, -w + 2, -2, 2])
        warp.extend([w - 2, w - 1, w + 1, w + 2])
        warp.extend([2 * w - 2, 2 * w - 1, 2 * w, 2 * w + 1, 2 * w + 2])

        unsearched = -1
        dist = [unsearched] * (self.height * self.width)
        dist[self.start] = 0
        queue = deque([self.start])
        while queue:
            x = queue.popleft()
            cur_dist = dist[x]

            for dx in move:
                nx = x + dx
                if self.grid[nx] == self.wall:
                    continue
                if dist[nx] == unsearched or dist[nx] > cur_dist:
                    dist[nx] = cur_dist
                    queue.appendleft(nx)

            for dx in warp:
                nx = x + dx
                if self.grid[nx] == self.wall:
                    continue
                if dist[nx] == unsearched or dist[nx] > cur_dist + 1:
                    dist[nx] = cur_dist + 1
                    queue.append(nx)

        return dist[self.goal]

    def debug(self):
        print(f"<DEBUG>\nstart={self.start}, goal={self.goal}", file=sys.stderr)
        for row in zip(*[iter(self.grid)] * self.width):
            print(*row, file=sys.stderr)


def main():
    H, W, CH, CW, DH, DW, *S = open(0).read().split()
    start, goal = (int(CH) - 1, int(CW) - 1), (int(DH) - 1, int(DW) - 1)
    maze = WarpableMaze(int(H), int(W), start, goal, S)
    # maze.debug()
    print(maze.bfs())


if __name__ == "__main__":
    main()


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

int main(){
	int line[31];
	int w, n;
	string str;
	getline( cin, str );
	sscanf( str.c_str(), "%d", &w );
	getline( cin, str );
	sscanf( str.c_str(), "%d", &n );

	for( int i=1; i<=w; i++ ){
		line[i] = i;
	}
	for( int i=0; i<n; i++ ){
		int a, b;
		getline( cin, str );
		sscanf( str.c_str(), "%d,%d", &a, &b );
		int tmp = line[a];
		line[a] = line[b];
		line[b] = tmp;
	}

	for( int i=1; i<=w; i++ ){
		cout << line[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int per[1000005];
void init() {
	per[0] = 1;
	REP(i, 1000005)per[i] = per[i - 1] * i % 1000003;
}
signed main() {
	init();
	int q; cin >> q; 
	while (q--) {
		int x, d, n; cin >> x >> d >> n;
		if (!d) {
			cout << mod_pow(x, n, 1000003) << endl;
		}
		else {
			int xd = x * mod_pow(d, 1000001, 1000003) % 1000003;
			if (xd + n - 1 >= 1000003)cout << 0 << endl;
			else {
				int memo = per[xd + n - 1] * (xd ? mod_pow(per[xd - 1], 1000001, 1000003) : 1) % 1000003;
				cout << memo * mod_pow(d, n, 1000003) % 1000003 << endl;
			}
		}
	}
}

Measured memory_bytes: 8704
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 2000000;
int main()
{
    int R[MAX], n;
    cin >> n;
    
    for(int i=0; i<n; i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv <<endl;
    return 0;
}


Measured memory_bytes: 3884
def gcd(a,b):
  if a%b==0:return b
  return gcd(b,a%b)

f=lambda x,y:x*y//gcd(x,y)
n,m=map(int,input().split())
s,t=input(),input()
lcm=f(n,m)
a,b=lcm//n,lcm//m
d={}

for i in range(n):
  d[i*a]=s[i]
for i in range(m):
  if i*b in d and d[i*b]!=t[i]:
    print(-1)
    break
  d[i*b]=t[i]
else:
  print(lcm)

Measured memory_bytes: 57708