akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program{

  static int n, ans, same;
  static string sa;

  static int Main() {

    n = int.Parse(Console.ReadLine());
    sa = Console.ReadLine();

    char[] s = sa.ToCharArray();

    for (int i = 1; i < n; i ++)
    {
      same = 0;
      for(int j = 0; j < i ; j ++)
      {
        bool yn = true;

        if (j != 0){
          for (int l = 0; l < j; l ++)
          {
            if (s[j] == s[l]) yn = false;
          }
        }

        if (yn)
        {
          for(int k = i; k < n; k ++)
          {
            if (s[j] == s[k])
            {
              same ++;
              break;
            }
          }
        }

      }
      if (same > ans) ans = same;
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define int long long
using namespace std;

const int INF = 1e9;
int n, m;
int ans = INF;
int a[85][85], b[85][85];
bool f[85][85][52000];

void attempt(int i, int j, int diff)
{

    if (i == n && j == m)
    {
        ans = min(ans, abs(diff + a[i][j] - b[i][j]));
        ans = min(ans, abs(diff - a[i][j] + b[i][j]));
        return;
    }
    if (f[i][j][diff])
        return;
    f[i][j][diff] = 1;

    if (i < n){
        attempt(i+1, j, abs(diff + a[i][j] - b[i][j]));
        attempt(i+1, j, abs(diff - a[i][j] + b[i][j]));
    }
    if (j < m){
        attempt(i, j+1, abs(diff + a[i][j] - b[i][j]));
        attempt(i, j+1, abs(diff - a[i][j] + b[i][j]));
    }

}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

//    freopen("in.inp", "r", stdin);
//    freopen("out.out", "w", stdout);

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> b[i][j];

    attempt(1, 1, 0);
    cout << ans;
}


Measured memory_bytes: 68608
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
using namespace std;

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

int main(){
	int n; cin>>n;
	int a[100001],b[100001];
	VE v;
	FOR(i,0,n){
		cin>>a[i];
		if(i%2==0) v.PB(a[i]);
	}
	sort(a,a+n);
	FOR(i,0,n){
		if(i%2==0) v.PB(a[i]);
	}
	sort(v.begin(), v.end());
	int st=v.size();
	uni(v);
	int en=v.size();
	//printf("%d %d\n",st,en);
	co((n+1)/2-(st-en));
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int n,s,a[2005];
bitset<4000005> f;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]),s+=a[i];
	f[0]=1;
	for (int i=1;i<=n;i++)
		f|=f<<a[i];
	int tmp=s-s/2;
	for (;!f[tmp];tmp++);
	printf("%d",tmp);
}

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

typedef long long ll;

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

    vector<ll> vec(5);
    string str;
    int cnt = 0;
    for(int i=0; i<n; i++){
        cin >> str;
        switch(str[0]){
            case 'M':
                vec.at(0)++;
                break;
            case 'A':
                vec.at(1)++;
                break;
            case 'R':
                vec.at(2)++;
                break;
            case 'C':
                vec.at(3)++;
                break;
            case 'H':
                vec.at(4)++;
                break;
        }
    }

    ll ans = 0;
    int bit = 0b00111;
    while(bit <= 0b11100){
        if(__builtin_popcount(bit) == 3){
            ll comb = 1;
            for(int i=0; i<5; i++){
                if(bit & 1<<i){
                    comb *= vec.at(i);
                }
            }
            ans += comb;
        }
        bit++;
    }

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

Measured memory_bytes: 256
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
 cin.tie(0);
 int n,k; cin >> n >>k;
 int a[n];
 forn(i,n) {
  cin >> a[i];
 }
 sort(a, a+n);
 int ans = 0;
 forn(i,k) {
 	ans += a[i];
 }
 cout << ans << endl;
return 0;
}


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

sum = 0
for i in range(1,n+1):
    sum += l + i -1

if l > 0 and l+n-1 > 0:
    sum = sum - l

elif l < 0 and 0 < l+n-1:
    sum = sum - 0

elif l < 0 and l+n-1 < 0:
    sum = sum - (l+n-1)

print(sum)


Measured memory_bytes: 3060
n,m,x = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(n)]

min_cost = 1200001
for i in range(2**n):
    cost = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if (i>>j) &1 == 1:
            cost += book[j][0]
            for k in range(m):
                skill[k] += book[j][k+1]
    if min(skill) >= x:
        min_cost = min(min_cost, cost)

print('-1' if min_cost == 1200001 else min_cost)

Measured memory_bytes: 9084
# ABC046 B - AtCoDeerくんとボール色塗り / Painting Balls with AtCoDeer
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N,K = nm()

if N == 1:
    print(K)
else:
    print(K*(K-1)**(N-1))



Measured memory_bytes: 2940
#include <iostream>

using namespace std;

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

    int d[N], i, a[101]={0}, sum=0;
    for(i=0; i<N; i++) {
        cin >> d[i];
        a[d[i]] += 1;
        if(a[d[i]]==1) sum += 1;
    }

    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
inline int inv(int x){return modpow(x,mod-2,mod);}
int n,a[100005];
int fact[100005],sum[100005];
signed main(){
	fact[0]=1;
	for(int i=1;i<=1e5;i++)fact[i]=fact[i-1]*i%mod;
	for(int i=1;i<=1e5;i++)sum[i]=(sum[i-1]+inv(i))%mod;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int ans=0;
	for(int i=1;i<n;i++){
		ans=(ans+sum[i]*(a[i+1]-a[i])%mod)%mod;
	}
	cout<<fact[n-1]*ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 2560
n = int(input())
nums = list(map(int, input().split()))

# 連続する3つの数の中で2番目の数が2番目に小さいような部分がいくつあるか？

counter = 0
for i in range(1, n - 1):
    # 値で降順ソートして2番目ならカウンター増やす
    d = {"i-1": nums[i - 1], "i": nums[i], "i+1": nums[i + 1]}
    sorted_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
    if sorted_d[1][0] == "i":
        counter += 1
print(counter)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
#define fa fflush(stdout); 
#define mp make_pair
using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
} 
const int N = 1e6 + 100;
const ll mod = 998244353;
const ll mod2 = 1e9 + 7;
ll fact[N];
void init()
{
	fact[0] = 1;
	for (int i = 1; i <= 2e5; i++)
	{
		fact[i] = fact[i - 1] * i;
		fact[i] %= mod;
	}
}
ll binpow (ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
		res %= mod;
		a %= mod;
	}
	return res;
}
int main () 
{
    data();
    init();         
   	ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for (int i = 0; i <= k; i++)
    {
    	ans += ((m * fact[n - 1] % mod * binpow(fact[i], mod - 2) % mod * binpow(fact[n - 1 - i], mod - 2)) % mod) % mod * binpow(m - 1, n - i - 1) % mod;
    	ans %= mod;
    }
    cout << ans;
}
//Timus:295965SY                                      
//1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
//2, 4, 6, 8, 10, 12, 14, 16, 17, 18
//3, 6, 9, 12, 15, 18, 21, 24, 27, 30
//5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, ,  


Measured memory_bytes: 5188
import sys
Input = sys.stdin.readline

N = int(Input())
x_y_h = [list(map(int, Input().split())) for _ in range(N)]
 
if N == 1:
    print("{0} {1} {2}".format(x_y_h[0][0], x_y_h[0][1], x_y_h[0][2]))
else:
    for c_x in range(0, 100+1):
        for c_y in range(0, 100+1):
            for x, y, h in x_y_h:
                if h > 0:
                    H = h + abs(c_x - x) + abs(c_y - y)
                    break
            for x, y, h in x_y_h:
                if h != max(H - abs(c_x - x) - abs(c_y - y), 0):
                    break
            else:
                print("{0} {1} {2}".format(c_x, c_y, H))
                sys.exit()

Measured memory_bytes: 3064
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(_i, s, e) for(_i = s; _i < e; ++_i)
#define FOR_INV(_i, s, e) for(_i = e - 1; _i >= s; --_i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;


class UnionFindTree{
public:
    UnionFindTree(LONG N){
        ranks.resize(N, 1);
        nums.resize(N, 1);
        parent.resize(N, -1);
    }

    LONG merge(LONG a, LONG b){
        LONG r_a = _root(a);
        LONG r_b = _root(b);

        if(r_a == r_b){
            return 0;
        }

        LONG ret = nums[r_a] * nums[r_b];

        if(ranks[r_a] < ranks[r_b]){
            parent[r_b] = r_a;
            ranks[r_a] = ranks[r_b] + 1;
            nums[r_a] += nums[r_b];
        }
        else{
            parent[r_a] = r_b;
            ranks[r_b] = ranks[r_a] + 1;
            nums[r_b] += nums[r_a];
        }

        return ret;
    }

    bool isSame(LONG a, LONG b){
        LONG r_a = _root(a);
        LONG r_b = _root(b);

        return r_a == r_b;
    }

private:
    vector<LONG> ranks;
    vector<LONG> nums;
    vector<LONG> parent;

    LONG _root(LONG a){
        if(parent[a] == -1){
            return a;
        }

        LONG r = _root(parent[a]);
        parent[a] = r;
        return r;
    }
};


int main(){
    LONG N, M;
    cin >> N >> M;

    UnionFindTree tree(N);
    LONG i;

    LVEC A(M), B(M);
    FOR(i, 0, M){
        cin >> A[i] >> B[i];
    }

    LVEC result(M + 1, 0);
    result[M] = N * (N - 1) / 2;
    FOR_INV(i, 0, M){
        LONG merge_num = tree.merge(A[i]-1, B[i]-1);
        result[i] = result[i+1] - merge_num;
        if(result[i] == 0){
            break;
        }
    }

    FOR(i, 0, M){
        cout << result[i + 1] << endl;
    }
}




Measured memory_bytes: 6016
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>

#ifdef PRINTERS
#include "printers.hpp"
using namespace printers;
#define tr(a)		cerr<<#a<<" : "<<a<<endl;
#else
#define tr(a)    
#endif

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;

void solve(){
	int N,M;
	cin>>N>>M;
	if(N>M)swap(N,M);
	if(M-N>1){
		cout<<0;
		return;
	}
	ll ans=1;
	for(int i=1;i<=N;i++){
		ans=(ans*i)%hell;
	}
	for(int i=1;i<=M;i++){
		ans=(ans*i)%hell;
	}
	if(N==M)ans=(ans*2)%hell;
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 892
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define MAXN   10000002 

int spf[MAXN]; 

void sieve() { 
  spf[1] = 1; 
  for (int i = 2; i < MAXN; i++) 
    spf[i] = i; 
  for (int i = 4; i < MAXN; i += 2) 
    spf[i] = 2; 

  for (int i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < MAXN; j += i) 
        if (spf[j]==j) 
          spf[j] = i; 
    } 
  } 
} 

int getdiv(int x) { 
  if (x == 1) return 1;
  vector<int> vc;
  while (x != 1) {
    int p = spf[x];
    int c = 0;
    while (x % p == 0) {
      c++;
      x /= p;
    }
    vc.pb(c);
  } 
  int p = 1;
  for (auto i: vc) p *= (i + 1);
  return p;
} 

int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  sieve();
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i * getdiv(i);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 81772
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int MOD = 1000000007;

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

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


int main(){
    std::ios_base::sync_with_stdio(false);

    int n; cin >> n;
    ll t; cin >> t;
    for(int i=1;i<n;i++){
        ll new_t; cin >> new_t;
        t = lcm(t, new_t);
    }

    cout << t << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//int n = sc.nextInt();
		String s = sc.next();
		long count=0;
		long l=0,x=0;
		//long[][] array=new long[n][2];
		if(s.equals("A")) {
			System.out.println("T");
		}else if(s.equals("T")) {
			System.out.println("A");
		}else if(s.equals("C")) {
			System.out.println("G");
		}else {
			System.out.println("C");
		}

		//System.out.println(count);
	}
}




Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	ll N, W,sum=0;
	cin >> N>>W;
	vector<ll>w(N+1,0);
	vector<ll>v(N+1,0);
	vector<vector<ll>>dp(N+1,vector<ll>(W+1,0));
	for (ll i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
	}
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < W + 1; j++) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j + w[i + 1] <= W) {
				dp[i + 1][j + w[i + 1]] =
					max(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]);
			}
		}
	}
	cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#define INF (1e9)
#define J 2000
#define N 50
using namespace std;
int main(){
  int n,c[N],dp[J],dn[J],C=0;
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<J;i++) dp[i]=dn[i]=INF;
    dp[0]=0;
    for(int i=0;i<n;i++)
      for(int j=1;j<J;j++)
	if(j>=c[i]) dp[j]=min(dp[j],dp[j-c[i]]+1);
    reverse(c,c+n);
    for(int i=0;i<J;i++){
      int cnt=0,sum=i;
      for(int j=0;j<n;j++){
	cnt+=sum/c[j];
	sum%=c[j];
      }
      if(sum==0) dn[i]=cnt;
    }
    int flag=0;
    for(int i=1;i<J;i++){
      if(dp[i]==INF||dn[i]==INF){
	flag=1;
	break;
      }
      if(dp[i]!=dn[i]){
	flag=2;
	break;
      }
    }
    C++;
    cout<<"Case #"<<C<<": ";
    if(!flag) cout<<"OK"<<endl;
    else if(flag==1) cout<<"Cannot pay some amount"<<endl;
    else cout<<"Cannot use greedy algorithm"<<endl;
  }
  return 0;
}

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

int main(void) {
    int X,A,B;

    cin >> X >> A >> B;
    if(B <= A) { 
        cout << "delicious\n";
    } else if(B <= (A+X)) {
        cout << "safe\n";
    } else {
        cout << "dangerous\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

int d[100];
int q[100][24];
int t[100];

int main() {
  int n;
  while(cin>>n,n) {
    REP(i,n) {
      cin >> d[i];
      cin >> t[i];
      int tmp[d[i]];
      REP(j,d[i]) cin >> tmp[j];
      REP(j,d[i]) q[i][j] = tmp[(j+t[i])%d[i]];
    }
    int t[4] = {13,17,19,23};
    int f[25];
    REP(i,25) {
      f[i] = -1;
      REP(j,4)if(i==t[j])f[i]=j;
    }
    int N = 55440;
    int ans = 0;
    REP(t,N) {
      int tmp = 0;
      REP(i,n) {
        if (f[d[i]] == -1) {
          tmp += q[i][t%d[i]];
        }
      }
      chmax(ans, tmp);
    }
    int hoge[4][25] = {};
    REP(i,n) {
      if (f[d[i]] >= 0) {
        REP(j,d[i]) hoge[f[d[i]]][j] += q[i][j];
      }
    }
    REP(i,4) {
      ans += *max_element(hoge[i],hoge[i]+25);
    }
    cout << ans << endl;
  }
}

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

int main() {
    int n;
    cin >>n;
    map<string, bool> S;
    string  cmd;
    string  op;
    for (int i=0; i<n; i++) {
        cin >>cmd >>op;
        if ("insert" ==cmd) {
            if (S.find(op)==S.end())
                S.insert(make_pair(op, true));
        } else if (S.find(op)!=S.end())
                cout <<"yes" <<endl;
            else
                cout <<"no" <<endl;
    }
    return 0;
}


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

using namespace std;

int mod = (int)1e9 + 7;

int main() {
    char c;
    int H, W;

    scanf("%d %d\n", &H, &W);
    vector<vector<int>> dp(H, vector<int>(W));

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%c\n", &c);
            if (!i && !j) {
                dp[i][j] = 1;
                continue;
            }
            if (c == '.') {
                if (i)
                    dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
                if (j)
                    dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
            }
        }
    }

    printf("%d\n", dp[H - 1][W - 1]);

    return 0;
}

Measured memory_bytes: 4224
# coding: utf-8
import sys
from collections import deque
 
ans = str(input())
n = int(input())
r = 2
be=deque()
af=deque()
 
for i in range(n) :
    x = input().split(" ")
    if int(x[0]) == 1 :
        r = r + 1
    else :
        pp = int(x[1])
        if r % 2 == 1 :
            pp = pp + 1
        if pp % 2  == 1 :
            be.appendleft(str(x[2]))
        else :
            af.append(str(x[2]))

ans = ''.join(be) + ans + ''.join(af)
if r % 2 == 1 :
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 6516
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
string pass;
int main()
{
  cin >>pass;
  bool flag1,flag2,flag3,flag4;
  flag1=flag2=flag3=flag4=false;
  if(pass.length()>=6){
    flag1 = true;
  }
  if(flag1){
  for(int i = 0;i < pass.length();i++){
    if(isdigit(pass[i])&&flag2==false){
      flag2 = true;
      }
    if(islower(pass[i])&&flag3==false){
      flag3 = true;
    }
    if(isupper(pass[i])&&flag4==false){
      flag4 = true;
    }
    if(flag1&&flag2&&flag3&&flag4){
      cout <<"VALID"<<endl;
      return 0;
    }
  }
  }
  cout <<"INVALID"<<endl;
  return 0;
}

Measured memory_bytes: 1180
while True:
    n, m = map(int,raw_input().split(' '))
    if n == 0:
        break
    scores = [0] * n
    for i in range(m):
        j = 0
        for s in map(int,raw_input().split(' ')):
            scores[j] += s
            j += 1
    print max(scores)



Measured memory_bytes: 4700
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
vector<int> Z_algo(const string &S) {
	int N = S.size();
	vector<int> z(N);
	z[0] = N;
	int i = 1, j = 0;
	while (i < N) {
		while (i + j < N && S[j] == S[i + j]) j++;
		z[i] = j;
		if (j == 0) { i++; continue; }
		int k = 1;
		while (i + k < N && k + z[k] < j) z[i + k] = z[k], k++;
		i += k; j -= k;
	}
	return z;
}
bool match[500001];
bool vis[500001];
int len[500001];
string s, t;
void calc(int pos) {
	if (vis[pos]) return;
	vis[pos] = 1;
	len[pos] = -1;
	if (!match[pos]) {
		len[pos] = 0;
		return;
	}
	int to = (pos + t.size()) % s.size();
	calc(to);
	if (len[to] != -1) len[pos] = len[to] + 1;
}
int main() {
	cin >> s >> t;
	string ss = s;
	while (ss.size() < t.size()) ss += s;
	ss += s;
	string x = t + "$" + ss;
	vector<int> z = Z_algo(x);
	for (int i = 0; i < s.size(); i++) {
		if (z[i + t.size() + 1] == t.size()) match[i] = 1;
	}
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		calc(i);
		if (len[i] == -1) {
			cout << -1 << endl;
			return 0;
		}
		ans = max(ans, len[i]);
	}
	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

bool reversecompare(int a, int b)
{
  return a > b;
}

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

  int N;
  int a[150];

  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> a[i];
  sort(a, a+N, reversecompare);

  int p1, p2;

  p1 = 0;
  p2 = 0;

  for (int i =0;i < N; i++) {
    if (i%2)
      p2 += a[i];
    else
      p1 += a[i];
  }

  cout << p1-p2 << endl;

  return 0;
}

Measured memory_bytes: 256
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def prime_factorize(n):
    a = {}
    while n % 2 == 0:
        if 2 in a:
            a[2] += 1
        else:
            a[2] = 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f in a:
                a[f] += 1
            else:
                a[f] = 1
            n //= f
        else:
            f += 2
    if n != 1:
        if n in a:
            a[n] += 1
        else:
            a[n] = 1
    return a
def main():
    N, M = map(int, input().split())
    d = prime_factorize(M)
    MOD = 10**9 + 7
    c = cmbs(MOD)
    r = 1
    for i in d:
        r *= c.cmb(N+d[i]-1, N-1)
    r %= MOD
    print(r)
main()


Measured memory_bytes: 122016
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
  	Scanner s = new Scanner(System.in);
    long n = s.nextLong();
    s.close();
    
    long sqr = Math.round(Math.sqrt(n));
    for(long i = sqr; i > 0; i--) {
      if (n % i == 0) {
        System.out.printf("%d", i + n / i - 2);
        return;
      }
    }

  }
}


Measured memory_bytes: 21972
n1=int(input())
def sieve(n):
  l=[]
  prime=[True for i in range(n)]
  prime[0]=False
  prime[1]=False
  for i in range(1,n):
    if prime[i]:
      l.append(i)
      num=n//i
      for j in range(2,num):
        prime[j*i]=False
  return l
l=sieve(100000)
index=0
count=0
ans=""
while count<n1:
  if l[index]%5==1:
    ans+=str(l[index])+" "
    count+=1
  index+=1
print(ans)

Measured memory_bytes: 4228
//$ node 181222B.js < 181222B.txt
//AJ
function Main(input) {
  input = input.split('\n') // 1行目がinput[0], 2行目がinput[1], …に入る
  for(var i=0;i<input.length;i++){
    var tmp = input[i].split(' ')
    input[i] = []
    for(var ii=0;ii<tmp.length;ii++){
      input[i].push(tmp[ii])
    }
  }
  var ans = 0
  for(var i=0;i<input[0];i++){
    var t = input[1][i]-input[2][i]
    if(0<t){
      ans += t
    }
  }
  console.log(ans)
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  if (stream2 == NULL) return 0;
#endif
  string s;
  while (cin >> s) {
    if (s == "#") break;
    int a, b, c; cin >> a >> b >> c;
    pair<pair<int,int> ,int> p = make_pair(make_pair(a, b), c);
    pair<pair<int,int> ,int> q = make_pair(make_pair(31, 4), 30);
    if (p > q) {
      cout << "? " << a - 30 << " " << b << " " << c << endl;
    } else {
      cout << "HEISEI " << a << " " << b << " " << c << endl;
    }
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  fclose(stream2);
#endif
  return 0;
}


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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int N;
	cin >> N;
	int arr[N];
	REP(i, 0, N) cin >> arr[i];
	
	int ans= 0;
	REP(i, 0, N){
		if(arr[i] > i && arr[arr[i]-1]-1 == i) ++ans;
	}
	cout << ans; 

}


Measured memory_bytes: 640
def main():
    while True:
        H, W = map(int, input().split())
        if H == 0 and W == 0:
            break
        for i in range(H):
            for j in range(W):
                if i % 2 == 0:
                    if j % 2 == 0:
                        print("#", end="")
                    else:
                        print(".", end="")
                else:
                    if j % 2 == 0:
                        print(".", end="")
                    else:
                        print("#", end="")
            print()
        print()
    return 0


if __name__ == "__main__":
    main()



Measured memory_bytes: 7008
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
using T3=tuple<int,int,int>;
vector<int> dx={0,1};
vector<int> dy={1,0};

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

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int h,w;
    cin>>h>>w;
    vector<vector<char>> f(h,vector<char>(w));
    rep(i,h)rep(j,w) cin>>f[i][j];
    vector<vector<int>> cnt(h,vector<int>(w,inf));
    if(f[0][0]=='#') cnt[0][0]=1;
    else cnt[0][0]=0;
    priority_queue<T3, vector<T3>, greater<T3>> bfs;
    bfs.emplace(cnt[0][0],0,0);
    int x,nx,y,ny,z;
    int i=0,j=0;
    int r=0;
    while(cnt[h-1][w-1]==inf){
        if(r%2==0 && i<w){
            if(f[j][i]=='.'){
               if(i>0) chmin(cnt[j][i],cnt[j][i-1]);
               if(j>0) chmin(cnt[j][i],cnt[j-1][i]);
            }
            if(f[j][i]=='#'){
                if(i>0 && f[j][i-1]=='#') chmin(cnt[j][i],cnt[j][i-1]);
                if(i>0 && f[j][i-1]=='.') chmin(cnt[j][i],cnt[j][i-1]+1);
                if(j>0 && f[j-1][i]=='#') chmin(cnt[j][i],cnt[j-1][i]);
                if(j>0 && f[j-1][i]=='.') chmin(cnt[j][i],cnt[j-1][i]+1);
            }
            i ++;
            continue;
        }
        if(i==w){
            i =j;
            j ++;
            r ++;
            continue;
        }
        if(r%2==1 && j<h){
            if(f[j][i]=='.'){
               if(i>0) chmin(cnt[j][i],cnt[j][i-1]);
               if(j>0) chmin(cnt[j][i],cnt[j-1][i]);
            }
            if(f[j][i]=='#'){
                if(i>0 && f[j][i-1]=='#') chmin(cnt[j][i],cnt[j][i-1]);
                if(i>0 && f[j][i-1]=='.') chmin(cnt[j][i],cnt[j][i-1]+1);
                if(j>0 && f[j-1][i]=='#') chmin(cnt[j][i],cnt[j-1][i]);
                if(j>0 && f[j-1][i]=='.') chmin(cnt[j][i],cnt[j-1][i]+1);
            }
            j ++;
            continue;
        }
        if(j==h){
            j=i+1;
            i ++;
            r ++;
            continue;
        }
    }
    cout<<cnt[h-1][w-1]<<endl;
}

Measured memory_bytes: 384
#import<iostream>
#import<set>
#import<algorithm>
using namespace std;main(){int n,k,c[10],i,t;for(;cin>>n>>k,i=n;){for(;i--;)cin>>c[i];sort(c,c+n);set<int>s;do{for(i=t=0;i<k;++i)t=t*(c[i]>9?100:10)+c[i];s.insert(t);}while(next_permutation(c,c+n));cout<<s.size()<<endl;}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

const ll sch = 200000;

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





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

    cout << ans << endl;
    
    

    


    return 0;
}


Measured memory_bytes: 4768
#include<stdio.h>

int main(void)
{
  long n,i,max=0,j;
  scanf("%ld",&n);
  long a[n];
  for(i=0;i<n;i++)
    {
      scanf("%ld",&a[i]);
    }
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  if(a[i]-a[j] > max)
	    {
	      max = a[i] - a[j];
	    }
	}
    }
  printf("%ld\n",max);
  return 0;
}

Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
XY = [list(mapint()) for _ in range(N)]

from itertools import combinations_with_replacement as cwr

ans = 10**20
for p1, p2, p3, p4 in cwr(XY, 4):
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    x4, y4 = p4
    lx, rx = min(x1, x2, x3, x4), max(x1, x2, x3, x4)
    ly, ry = min(y1, y2, y3, y4), max(y1, y2, y3, y4)
    cnt = 0
    for x, y in XY:
        if lx<=x<=rx and ly<=y<=ry:
            cnt += 1
    if cnt>=K:
        ans = min(ans, (rx-lx)*(ry-ly))

print(ans)
    

Measured memory_bytes: 82436
var n,i,a,x,v:longint;
function hs(s:longint):longint;
begin
  while s mod 2=0 do
   begin
    s:=s div 2;
    inc(v);
   end;
 hs:=v;
 v:=0;
end;
 begin
  readln(n);
  x:=2100000000;
  for i:=1 to n do
  begin
   read(a);
   if hs(a)<=x then
    x:=hs(a);
  end;
  writeln(x);
 end.




Measured memory_bytes: 128
import itertools
H,W,K = map(int,input().split())
V = [list(input()) for i in range(H)]
ans = 0
for i in list(itertools.product(range(2), repeat=H)):
  for j in list(itertools.product(range(2), repeat=W)):
    temp = 0
    for k in range(H):
      for l in range(W):
        if V[k][l] == '#':
          if i[k] == 1:
            if j[l] == 1:
              temp += 1
    if temp == K:
      ans += 1
print(ans)

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

import sys


def main():
    while True:
        cards = sys.stdin.readline().strip('\n')
        if cards == '-':
            break
        for shuffle in range(int(sys.stdin.readline().strip('\n'))):
            h = int(sys.stdin.readline().strip('\n'))
            cards = cards[h:] + cards[:h]
        print(cards)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


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

  long long s[n] ,scoreSum = 0;
  rep(i,n){
    cin >> s[i];
    scoreSum += s[i];
  }

  sort(s,s+n);

  if(scoreSum % 10){
    cout << scoreSum << endl;
    return 0;
  }
  rep(i,n){
    if(s[i] % 10){
      cout << scoreSum - s[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n,z;
    vector<P> p;
    cin>>n;
    z=(n/2)*2+1;
    for(int i=1;i<z-1;i++){
        for(int j=i+1;j<z;j++){
            if(j!=z-i){
                p.push_back(P(i, j));
            }
        }
    }
    if(n==z){
        for(int i=1;i<n;i++){
            p.push_back(P(n, i));
        }
    }
    int m=p.size();
    cout<<m<<endl;
    for(int i=0;i<m;i++){
        cout<<p[i].first<<" "<<p[i].second<<endl;
    }
}


Measured memory_bytes: 384
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n;
            cin>>n;
            if(n>=30)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000


int main(){
  char buf[1024];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  int *V=(int *)malloc(sizeof(int)*N);
  rep(i,N){
    scanf("%d",&V[i]);
  }

  int *C=(int *)malloc(sizeof(int)*N);
  rep(i,N){
    scanf("%d",&C[i]);
  }

  int ans=0;

  rep(i,N){
    if(V[i]-C[i]>0){
      ans+=V[i]-C[i];
    }
  }

  printf("%d\n", ans);

  return 0;


}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
  int dx = tx - sx;
  int dy = ty - sy;
  std::cout << string(dx,'R') << string(dy,'U');
  std::cout << string(dx,'L') << string(dy,'D');
  std::cout << 'D' << string(dx+1,'R') << string(dy+1,'U') << 'L';
  std::cout << 'U' << string(dx+1,'L') << string(dy+1,'D') << 'R';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main() {
    int no, leg;
    scanf("%d %d", &no, &leg);
    for (int i = 0; i <= no; i++) {
        if (i*2 + (no-i)*4 == leg) {
            printf("Yes\n");
            exit(0);
        }
        
    }
    printf("No\n");
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b,s,i,x;
	s=100;
	x=0;
	for(i=0;i<4;i++){
		cin>>a;
		if(s>a) s=a;
		x=x+a;
	}
	x=x-s;
	s=100;
	for(i=0;i<2;i++){
		cin>>b;
		if(s>b) s=b;
		x=x+b;
	}
	x=x-s;
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
    
  while (input.hasNext()) {
    val A = input.nextLong()
    val B = input.next()
    val ans = ((A * ((B[0] - '0') * 100)) + (A * B.substring(2).toLong())) / 100
    
    println(ans)
  }
}

Measured memory_bytes: 36392
#include<bits/stdc++.h>
#define ff(x,a,b) for(int x=a;x<=b;x++)
using namespace std;
int n,m,a[505][505],mark[505],ans,sum,s[505],t[505],tt[505];
int main(){    cin>>n>>m;    ff(i,1,n) ff(j,1,m) cin>>a[i][j];    ans=n;ff(i,1,n) t[i]=a[i][1];ff(i,1,n) tt[i]=1;sum=m;    while(sum>0)    {        ff(i,1,m) s[i]=0;        ff(i,1,n) s[t[i]]++;        int k=1;        ff(i,2,m) if(s[k]<s[i]) k=i;        ans=min(ans,s[k]);        mark[k]=1;sum--;        ff(i,1,n) while(mark[t[i]]==1) t[i]=a[i][++tt[i]];    }    cout<<ans;}

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define debug(x) cout << x << endl;
#define endl '\n'
#define sz(x) (int)x.size()
#define popcount __builtin_popcount
#define MAXN 200005
#define LOG 20
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define int long long

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

int n;
string s;

int32_t main(){
    fastio
    cin >> n;
    cin >> s;

    int res = 0;
    char past = ' ';
    for(char c : s){
        if(past != c) res++;
        past = c;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3780
import java.util.*;

public class Main {
    public static final long MOD = 1000000007;
    int N,K;
    long[] A;

    public Main() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        K = scanner.nextInt();

        if (N == K){
            long R = 1;
            for (int i = 0; i < N; i++) {
                R = R * scanner.nextLong() % MOD;
                if(R < 0) R += MOD;
            }
            System.out.println(R);
            return;
        }

        A = new long[N];

        boolean allMinus = true;
        for (int i = 0; i < N; i++) {
            long in = scanner.nextLong();
            allMinus = allMinus && in < 0L;
            A[i] = in;
        }

        if(allMinus && (K & 1) == 1){
            allMinus();
        } else {
            searchMax();
        }
    }

    void searchMax(){
        Arrays.sort(A);

        long R = 1L;
        int max1 = N-1, max2 = N-2, min1 = 0, min2 = 1;

        while(K > 0){
            if(K == 1){
                R = R * A[max1] % MOD;
                break;
            }

            if(A[max1] * A[max2] > A[min1] * A[min2]){
                R = R * A[max1] % MOD;

                max1 = max2;
                max2 -= 1;
                K -= 1;
            } else {
                R = R * (A[min1] * A[min2] % MOD) % MOD;
                
                min1 += 2;
                min2 += 2;
                K -= 2;
            }
        }

        System.out.println(R);
    }

    void allMinus(){
        Arrays.sort(A);

        long R = 1L;
        for (int i = 0; i < K; i++) {
            R = R * A[N-1-i] % MOD;
            R += MOD;
        }

        System.out.println(R);
    }

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


Measured memory_bytes: 62136
// by syu
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var in = NewScanner(os.Stdin, 0)

func main() {
	n := in.ArrayInt(4)
	sort.Ints(n)
	if n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9 {
		Pln("YES")
	} else {
		Pln("NO")
	}
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 1048576
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}
func (s *Scanner) Int() int {
	s.Scan()
	i, e := strconv.ParseInt(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}
func (s *Scanner) ArrayInt(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = s.Int()
	}
	return r
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}
func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for start < len(data) && isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func Pln(s ...interface{}) {
	fmt.Println(s...)
}

type ByteSlice []byte
type IntSlice []byte


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Union_Find_Tree{
	public:
	int n;
	vi Par;
	Union_Find_Tree(int n){
		Par=vi(n);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		Par[x]=y;
		return 1;
	}
	bool Same(int x,int y){
		return Find_Par(x)==Find_Par(y);
	}
};

int n,m,q;

int main(){
	cin>>n>>m>>q;
	Union_Find_Tree uft(n+m);
	for(int i=0;i<q;i++){
		int t,u,v;
		cin>>t>>u>>v;
		u--;v--;
		if(t==1){
			int pu=uft.Find_Par(u),pv=uft.Find_Par(v);
			if(pu>=n&&pv>=n&&pu!=pv){
				cout<<i+1<<endl;
				return 0;
			}
			if(pu>=n) swap(u,v);
			uft.Unite(u,v);
		}
		else{
			int pu=uft.Find_Par(u);
			if(pu>=n&&pu-n!=v){
				cout<<i+1<<endl;
				return 0;
			}
			uft.Unite(u,v+n);
		}
	}
	cout<<0<<endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        int s;
        cin >> s; s--;
        a[i] = s;
    }
    vector<bool> visited(n);
    rep(i, n) visited[i] = false;
    
    int num = 0, cnt = 0;
    bool flag = false;
    while(true){
        if (visited[num]) break;
        if (num == 1) {
            flag = true;
            break;
        }
        visited[num] = true;
        num = a[num];
        cnt++;
    }
    if (flag) {
        cout << cnt << endl;

    } else {
        cout << -1 << endl;
    }


}

Measured memory_bytes: 3788