akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main 
{
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) 
	{
//		System.out.println("START");
		
		
		int dataSetNum = scan.nextInt();
		List<DataSet> dataSets = new ArrayList<DataSet>();
		
		for(int i = 0; i < dataSetNum; i++)
		{
			dataSets.add(new DataSet());
		}
		for(int i = 0; i < dataSetNum; i++)
		{
			System.out.println(dataSets.get(i).getAnswer());
		}

	}

	static class Method
	{
		int type; //0 for tan, 1 for fuku/compound
		double interest;
		int cost;
		DataSet dataSet;
			
		public Method(DataSet dataSet)
		{
//			System.out.println("Constructing method");
			
			type = scan.nextInt();
			interest = scan.nextDouble();
			cost = scan.nextInt();
			
//			type = Integer.parseInt(scan.next());
//			interest = Double.parseDouble(scan.next());
//			cost = Integer.parseInt(scan.next());
			this.dataSet = dataSet;
			
//			System.out.println("Method constructed: type " + type + " interest " + interest + " cost " + cost);
		}
		
		public int calculate()
		{
			double money = dataSet.startingMoney;
			double celengan = 0;
			
			double curInterest;
			
			for(int year = 0; year < dataSet.years; year++)
			{
				curInterest =  Math.floor(money * interest);
				
				if(type == 0)
				{
					celengan += curInterest;
				}
				else if(type == 1)
				{
					money += curInterest;
				}
				
				money -= cost;
			}
			
			return (int) (money + celengan);
		}
	}
	
	static class DataSet
	{
		double startingMoney;
		double years;
		List<Method> methods = new ArrayList<Method>();
		double numOfMethods;
		
		int answer;
		
		public int getAnswer()
		{
			return answer;
		}

		public DataSet()
		{
			startingMoney = scan.nextInt();
			years = scan.nextInt();
			numOfMethods = scan.nextInt(); 
			
			double biggestMoneyYet = -99999;
			for(int i = 0; i < numOfMethods; i++)
			{
				methods.add(new Method(this));
				
				int ret = methods.get(i).calculate();
				
				if(i == 0) {biggestMoneyYet = ret;}
				else
				{
					if(ret > biggestMoneyYet) {biggestMoneyYet = ret;}
				}
			}
			
			answer = (int) Math.floor(biggestMoneyYet);
			//constructor
		}
	}
}


Measured memory_bytes: 56848
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N, M;
	std::cin >> N >> M;
	std::map<std::int64_t, int> count;
	for (int i : boost::irange(0, N))
	{
		std::int64_t A;
		std::cin >> A;
		++count[A];
	}
	for (int i : boost::irange(0, M))
	{
		int B;
		std::int64_t C;
		std::cin >> B >> C;
		count[C] += B;
	}
	std::int64_t sum = 0;
	int rest = N;
	for (auto p : count | adaptor::reversed)
	{
		auto v = p.first;
		auto c = p.second;
		if (rest <= c)
		{
			sum += rest * v;
			break;
		}
		else
		{
			rest -= c;
			sum += c * v;
		}
	}
	std::cout << sum << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 12800
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define bql 2147483647
#define ll long long
#define ull unsigned long long
using namespace std::tr1;
using namespace std;
const int N=2e5+5;
const int mod=998244353;
const int fx[5]={0,-1,0,1,0};
const int fy[5]={0,0,-1,0,1};
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0' && ch<='9'){x=(x<<3)+(x<<1);x+=(ch-'0');ch=getchar();}
    return x*f;
}

void write(int x)
{
    if (x<0) putchar('-'),x=-x;
    if (x>10) write(x/10);
    putchar(x%10+'0');
}

ll n,k,a[N];
ll f(ll mid)
{
	ll ret=0;
	for (int i=0;i<n;i++)
  {
		if (a[i]==0)
    {
			if (mid>=0)
          ret+=n-1;
			continue;
		}
		if (a[i]<0)
    {
			ll target=mid/a[i];
			if (target*a[i]>mid)
          target++;
			int idx=lower_bound(a,a+n,target)-a;
			ret+=n-idx;
			if (idx<=i)
          ret-=1;
		}
		else
    {
			ll target=mid/a[i];
			if (target*a[i]>mid)
          target--;
			int idx=upper_bound(a,a+n,target)-a-1;
			if (idx<0)
          continue;
			ret+=idx+1;
			if (idx>=i)
          ret-=1;
		}
	}
	return ret/2;
}

int main()
{
	cin>>n>>k;
	for (int i=0;i<n;i++)
      cin>>a[i];
	sort(a,a+n);
	ll lo=-1e18,hi=1e18;
	while (lo<hi)
  {
		ll mid=lo+(hi-lo)/2;
		if (f(mid)>=k)
        hi=mid;
		else
        lo=mid+1;
	}
	cout<<lo<<endl;
	return 0;
}
//dfsd

Measured memory_bytes: 1792
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	int f=0,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
#define MAXN 200000
#define INF 0x3f3f3f3f
priority_queue<int> Q;
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++)
		Q.push(read());
	for(int i=1;i<=m;i++){
		int u=Q.top();Q.pop();
		Q.push(u/2);
	}
	LL sum=0;
	while(!Q.empty())
		sum+=Q.top(),Q.pop();
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 892
t = input().split(" ")

N = int(t[0])
K = int(t[1])

p = list(map(int,input().split(" ")))

ans = 0
a =0

for i in range(len(p)):
    #a = list(range(1,p[i]+1))
    #print(a)
    p[i] = ((p[i]*(p[i]+1))/2)/p[i]
    a += p[i]
    
    if i >= K-1:
        
        if i >= K:
            a += -(p[i-K])
        if a > ans:
            ans = a

print(ans)

    
    






Measured memory_bytes: 24812
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	// n個の数列から奇数番目のvの個数を求める配列
	vector<int> odds(100001, 0);
	// n個の数列から偶数番目のvの個数を求める配列
	vector<int> evens(100001, 0);
	// 入力されたvの値が何個あるのかを数えるための対応
	// iが奇数の場合は、奇数番目の配列へ、iが偶数のの場合は偶数番目の配列へ
	for (int i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		if (i % 2 == 0)
		{
			odds[v]++;
		}
		else {
			evens[v]++;
		}
	}
	
	
	// 奇数番目の配列の最大値と2番目に大きい値を求める
	int odds_1 = 0;
	int odds_2 = 0;
	// 偶数番目の配列の最大値と2番目に大きい値を求める
	int evens_1 = 0;
	int evens_2 = 0;
	
	for (int i = 1; i <= 100000; i++)
	{
		// 奇数番目の配列の計算
		if (odds[i] >= odds[odds_1])
		{
			odds_2 = odds_1;
			odds_1 = i;
		}
		else if (odds[i] >= odds[odds_2])
		{
			odds_2 = i;
		}
		
		// 偶数番目の配列の計算
		if (evens[i] >= evens[evens_1])
		{
			evens_2 = evens_1;
			evens_1 = i;
		}
		else if (evens[i] >= evens[evens_2])
		{
			evens_2 = i;
		}
	}
	
	// 出力
	int answer = 0;
	if (odds_1 != evens_1)
	{
		answer = n - odds[odds_1] - evens[evens_1];
	}
	else {
		if (odds[odds_1] - odds[odds_2] <= evens[evens_1] - evens[evens_2])
		{
			answer = n - odds[odds_2] - evens[evens_1];
		}
		else {
			answer = n - odds[odds_1] - evens[evens_2];
		}
	}
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define L(_i,_N) for(int _i=0;_i<_N;_i++)
typedef long long int lli;
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b) {
		int Count = 0;
		a += b;
		while (a > 0) {
			a /= 10;
			Count++;
		}
		cout << Count << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int n,c,t,ans=250000001,x;
int d[31][31];
map <int,int> colz;
map <int,int> colo;
map <int,int> colt;

int main(){
	cin>>n>>c;
	for(int i=0;i<c;i++){
		for(int j=0;j<c;j++){
			cin>>t;
			d[i+1][j+1]=t;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>t;
			if((i+j)%3==0){
				colz[t]++;
			}else if((i+j)%3==1){
				colo[t]++;
			}else{
				colt[t]++;
			}
		}
	}
	for(int i=1;i<=c;i++){
		for(int j=1;j<=c;j++){
			if(i!=j){
				for(int k=1;k<=c;k++){
					if(i!=k&&j!=k){
						for(int l=1;l<=c;l++){
							x+=colz[l]*d[l][i];
							x+=colo[l]*d[l][j];
							x+=colt[l]*d[l][k];
						}
						ans=min(ans,x);
						x=0;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int n,m,c,count = 0,a,x = 0;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i = 0; i < m; i++){
    cin >> b.at(i);
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a;
      x += a * b.at(j);
    }
    if(x + c > 0){
      count++;
    }
    x = 0;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int a[8];
	int b;
	int n;
	cin>>n;
	for(int z=0;z<n;z++){
	  cin>>b;
	 

	

	a[0]=b/10000000;
	a[1]=b/1000000-(a[0]*10);
	a[2]=b/100000-(a[0]*100+a[1]*10);
	a[3]=b/10000-(a[0]*1000+a[1]*100+a[2]*10);
	a[4]=b/1000-(a[0]*10000+a[1]*1000+a[2]*100+a[3]*10);
	a[5]=b/100-(a[0]*100000+a[1]*10000+a[2]*1000+a[3]*100+a[4]*10);
	a[6]=b/10-(a[0]*1000000+a[1]*100000+a[2]*10000+a[3]*1000+a[4]*100+a[5]*10);
	a[7]=b%10;
        
       sort(a,a+8);
	int y=a[0]*10000000+a[1]*1000000+a[2]*100000+a[3]*10000+a[4]*1000+a[5]*100+a[6]*10+a[7];
	    
	int x=a[7]*10000000+a[6]*1000000+a[5]*100000+a[4]*10000+a[3]*1000+a[2]*100+a[1]*10  +a[0];	
		
	cout<<x-y<<endl;
}
return 0;
}			
		

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long sum=0;
	for (int i=1;i<=n;i++)
		if (i%3!=0 && i%5!=0)
			sum+=i;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
import sys
from collections import deque
def main():
    input=sys.stdin.readline
    n,q=map(int,input().split())

    edge=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1;v-=1
        edge[u].append(v)
   
    cost=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        cost[p]+=x

    for idx,e in enumerate(cost):
        if e==0:continue
        for f in edge[idx]:
            cost[f]+=e

    print(*cost)

if __name__ == "__main__":
    main()

Measured memory_bytes: 48272
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
main()
{
    long long a,b;cin>>a>>b;
    long long c=a,cnt=1;
    while(a<b)
    {
        a+=c-1;
        cnt++;
    }
    if(b==1)cout<<0<<endl;
    else  cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::stdin;

#[allow(dead_code)]
fn input_ints() -> Vec<u64> {
    let mut st = String::new();
    match stdin().read_line(&mut st) {
        Ok(_) => st.split_whitespace().map(|s| s.parse().unwrap()).collect(),
        Err(_) => "".split_whitespace().map(|s| s.parse().unwrap()).collect(),
    }
}

#[allow(unused_variables)]
fn solve() {
    let n = input_ints()[0];
    let ns = input_ints();

    let total: u64 = ns.iter().fold(0, |t, i| t+i);

    if total % 2 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 2684
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;

string S;
int x;
pair< string, cp2 > A[112];

int main(){
    
    cin>>N;
    REP( i, N ){
        cin>>S>>x;
        A[i] = cp3( S, cp2( -x, i+1 ) );
    }
    sort( A, A+N );
    
    REP( i, N ) cout<<A[i].thr<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#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>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    ll ans = 0;
    if (N == 1)
        ans = 0;
    else
        ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
#include<functional>
#define ll long long
using namespace std;

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int W, a, b; cin >> W >> a >> b;
	int d = max(a, b) - (min(a, b) + W);
	if (d < 0) { cout << 0 << endl; }
	else { cout << d << endl; }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'
int n,m,x;
vector<vector<int>> a;
vector<int> cost;
// bool check1=true;
int mincost(vector<int> fk,int remain)
{
    bool flag=true;
    for (int i = 0; i < m; i++)
    {
        if(fk[i]<x)
        {
            flag=false;
        }
        /* code */
    }
    if(flag==true)
    {
        // if(remain==-1)
            // check1=true;
        return 0;
    }
    if(remain==-1)
    {
        // check1=false;
        return 10000000;
    }
    vector<int> fktemp(m,0);
    for (int i = 0; i < m; i++)
    {
        fktemp[i]=fk[i]+a[remain][i];
    }
    return min(cost[remain]+mincost(fktemp,remain-1),mincost(fk,remain-1));
}
int main()
{
    IOS;
    cin>>n>>m>>x;
    a.resize(n,vector<int>(m,0));
    cost.resize(n,0);
    for (int i = 0; i < n; i++)
    {
        cin>>cost[i];
        for (int j = 0; j < m; j++)
        {
            cin>>a[i][j];
        }
    }
    vector<int> fk(m,0);
    int ans=mincost(fk,n-1);
    if(ans>=10000000)
    {
        cout<<-1;
    }
    else
    {
        cout<<ans;
    }
    
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<algorithm>
#include <map>  
#include <string.h>
#include <math.h>

using namespace std;



int main()
{	

	int count=0;
	string s;
	cin >> s;

	for (int i = 1; i < 4; i++) {
		if (s[i-1] == s[i])count++;
		else count = 0;
		if (count == 2) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <locale>

using namespace std;

int main(int argc, char *argv[]) {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k - 1] = tolower(s[k - 1]);
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import combinations


def is_square(n):
    k = 1
    while k ** 2 < n:
        k += 1
    return k ** 2 == n


def main():
    n, d = map(int, input().split())
    xxs = [list(map(int, input().split())) for _ in range(n)]
    res = 0
    for (ys, zs) in combinations(xxs, 2):
        dist2 = sum((y - z) ** 2 for (y, z) in zip(ys, zs))
        if is_square(dist2):
            res += 1
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<double> materialList;
	for(int i = 0 ; i < n;i ++){
		double num;
		cin>>num;
		materialList.push_back(num);
	}
	while( materialList.size() != 1){
		sort(materialList.begin(),materialList.end(),greater<int>());
		int index = materialList.size() - 1;
		double num = (materialList[index] + materialList[index-1])/2;
		materialList.pop_back();
		materialList.pop_back();
		materialList.push_back(num);
	}
	printf("%.7lf\n",materialList[0]);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define eps 10E-10
#define mod 998244353
#define pai acos(-1)
#define N 1000005


vector<ll>prime;
bool vis[1000005];

void sieve()
{
    ll sr,n=1000004;
    sr=sqrt(n);
    prime.pb(2);
    for(int i=3;i<=sr;i+=2){
        if(!vis[i]){
            for(int j=i*i;j<=n;j+=2*i){
                vis[j]=1;
            }
        }
    }
    for(ll i=3;i<=n;i+=2){
        if(!vis[i]) prime.pb(i);
    }
    return ;
}

ll bs(ll n){
   ll lo=1,hi=n,mid,ans;
   while(lo<=hi){
      mid=(lo+hi)/2;
      if((mid*(mid+1))/2<=n) ans=mid,lo=mid+1;
      else hi=mid-1;
   }
   return ans;
}

int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
//   freopen("in.txt","r",stdin);
//   freopen("out.txt","w",stdout);
   sieve();
   ll n,ans=0,p;
   cin>>n;
   for(int i=0;i<prime.size()&&prime[i]*prime[i]<=n;i++){
      if(n%prime[i]==0){
         ll cnt=0;
         p=prime[i];
         while(n%p==0) n/=p,cnt++;
         ans+=bs(cnt);
      }
   }
   if(n>1) ans++;
   cout<<ans<<endl;
   return 0;
}


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

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

int main(){
	for(int n; cin >> n && n;) {
		bool next = true, left = false, right = false;

		int ans = 0;
		rep(i, n) {
			string f;
			cin >> f;

			(f[0] == 'l' ? left : right) = (f[1] == 'u' ? true : false);

			if(next == left && next == right) {
				next = !next;
				++ans;
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
n = int(input())
a = list(map(int,input().split()))
cnt = 0
flag = True
while(flag):
    flag = False
    for j in list(range(1,n))[::-1]:
        if a[j] < a[j-1]:
            temp = a[j]
            a[j] = a[j-1]
            a[j-1] = temp
            flag = True
            cnt += 1
ans = str(a[0])
for i in a[1:]:
    ans += ' '+ str(i)
print(ans)
print(cnt)


Measured memory_bytes: 5596
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


def main():
    n, r = map(int, input().split())
    if n <= 10:
        # r = x - (100 * (10 - n))
        print(r + 100 * (10 - n))

    else:
        print(r)


if __name__ == '__main__':
    main()


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

int main(){
    long A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<=A) cout << K << endl;
    else if(K<=A+B) cout << A << endl;
    else cout << A-(K-A-B) << endl;
}

Measured memory_bytes: 3612
import sys

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))


max_a = max(A)
if K > max_a:
    print("IMPOSSIBLE")
    sys.exit()


A.sort()

diffs = set()
for i in range(N-1):
    diffs.add(A[i+1] - A[i])

if 1 in diffs:
    print("POSSIBLE")
    sys.exit()

for a_i in A:
    if a_i - K in diffs or a_i == K:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14224
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int K = GetInt();
		int L = GetInt();

		UnionFind ufRoad = new UnionFind(N+1);
		for(int i = 0; i < K; i++)
		{
			int p = GetInt();
			int q = GetInt();
			if(!ufRoad.IsSame(p,q))
				ufRoad.Merge(p,q);
		}
		
		UnionFind ufRailway = new UnionFind(N+1);
		for(int i = 0; i < L; i++)
		{
			int r = GetInt();
			int s = GetInt();
			if(!ufRailway.IsSame(r,s))
				ufRailway.Merge(r,s);
		}

		Dictionary<Tuple<int, int>, int> num = new Dictionary<Tuple<int, int>, int>(N);
		List<Tuple<int, int>> pairs = new List<Tuple<int, int>>();
		for(int i = 1; i <= N; i++)
		{
			int currentNum = 0;
			var key = Tuple.Create(ufRoad.Root(i), ufRailway.Root(i));
			num.TryGetValue(key, out currentNum);
			num[key] = currentNum + 1;
			pairs.Add(key);
		}

		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < N; i++)
			sb.AppendFormat($"{num[pairs[i]]} ");
		Console.WriteLine(sb);
	}
}


public class UnionFind
{
	private int[] par = null;
	private int[] rank = null;
	private int[] ccSize = null;
	
	public UnionFind(int n)
	{
		par = new int[n];
		rank = new int[n];
		ccSize = new int[n];
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			ccSize[i] = 1;
		}
	}

	public bool IsSame(int x, int y)
	{
		return (Root(x) == Root(y));
	}

	public int Root(int x)
	{
		if(par[x] == x)
			return x;

		int r = Root(par[x]);
		par[x] = r;
		return r;
	}
	
	public bool Merge(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry)
			return false;
		
		if(rank[rx] < rank[ry])
		{
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		else if(rank[rx] == rank[ry])
			rank[rx]++;

		par[ry] = rx;
		ccSize[rx] = ccSize[rx] + ccSize[ry];
		return true;
	}

	public int Size(int x)
	{
		return ccSize[Root(x)];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 39756
#include<iostream>
#include<cstdio>
#include<complex>
#include<vector>
#include<cmath>
using namespace std;
typedef complex<double> P;
vector<P> coor;
double calarea();
double divtri(int i, int j);

int main(){
    double tmpx, tmpy;
    while(scanf("%lf,%lf", &tmpx, &tmpy) != EOF){
        coor.push_back(P(tmpx, tmpy));
    }
    printf("%f\n", calarea());
    return 0;
}

double calarea(){
    double ans = 0;
    for(int i = 0; i < coor.size() - 1; i++){
        ans += divtri(i, i + 1);
    }
    ans += divtri(coor.size() - 1, 0);
    return ans;
}

double divtri(int i, int j){
    return abs(imag(conj(coor[i]) * coor[j])) / 2;
}

Measured memory_bytes: 0
using System;
namespace csharptest
{
    class Program
    {
        static void Main(string[] args)
        {
            long count = 0;
            long[] ans = new long[100000];
            string str=Console.ReadLine();
            do
            {
                char[] s = str.ToCharArray();
                ans[count] = 0;
                for (int m = 0; m < s.Length; m++)
                {
                    ans[count] += long.Parse(s[m].ToString());
                }
                count++;
                str = Console.ReadLine();
            } while (str != "0");
            for (int m = 0; m < count; m++)
            {
                Console.WriteLine(ans[m]);
            }
        }
    }
}

Measured memory_bytes: 6432
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

def main():
	n=II()
	s=input().rstrip().decode()
	li=[0]*n
	
	q=II()
	K=LI()
	for k in K:
		D=0
		M=0
		DM=0
		ans=0
		
		for i in range(n):
			if s[i]=="D":
				D+=1
			elif s[i]=="M":
				M+=1
				DM+=D
			elif s[i]=="C":
				ans+=DM
			
			if i-k+1>=0:
				if s[i-k+1]=="D":
					D-=1
					DM-=M
				elif s[i-k+1]=="M":
					M-=1
		print(ans)
		


if __name__ == "__main__":
	main()


Measured memory_bytes: 82568
import Data.List (partition, foldl')

mk [x,y,z] = (x,y,z)

a#b = abs (a-b)

solv :: [(Int,Int,Int)] -> [(Int,Int,Int)]
solv xs
  = foldl' lt (foldl' eq [(cx,cy,h0+x0#cx+y0#cy)|cx<-[0..100], cy<-[0..100]] nzs) zs
  where
    eq :: [(Int,Int,Int)] -> (Int,Int,Int) -> [(Int,Int,Int)]
    eq xs' (x,y,h) = filter (\(cx,cy,ch)->ch==h + x#cx + y#cy) xs'
    lt :: [(Int,Int,Int)] -> (Int,Int,Int) -> [(Int,Int,Int)]
    lt xs' (x,y,h) = filter (\(cx,cy,ch)->ch<=x#cx + y#cy) xs'
    (nzs@((x0,y0,h0):_), zs) = partition (\(_,_,h)-> h>0) xs

main = do
  getLine
  ps <- map (mk.map read.words) . lines <$> getContents :: IO [(Int,Int,Int)]
  let (x,y,h):_ = solv ps
  putStrLn . unwords . map show $ [x,y,h]


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string S;
  cin>>S;
  if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll INF = 1LL << 60; //MAX 9223372036854775807

int main()
{
ll h , n ;
cin >> h >> n ;
vector<ll> a(n);
vector<ll> b(n);
rep(i, n){
  cin >> a[i] >> b[i];
}
vector<ll> dp(h+1,INF);
dp[0]=0;
rep(i,n){
  rep(j,h+1){
    if(j-a[i]<0)dp[j]=min(dp[j],b[i]);
    else dp[j]=min(dp[j],b[i]+dp[j-a[i]]);
  }
}

cout << dp[h] << endl;
return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.close();
		int a2 = a*a;
		int a3 = a*a*a;
		System.out.println(a+a2+a3);

	}

}


Measured memory_bytes: 35788
#include <cstdio>
#include <set>
#include <algorithm>
#include <cmath>

int cnt[500005];
int a[500005];
int block;

struct A{
    int l, r;
    int idx;
    int ans;
}q[500005];

bool cmp(A a, A b){
    if(a.l / block != b.l / block)
        return a.l / block < b.l / block;
    return a.r < b.r;
}

bool cmp2(A a, A b){return a.idx < b.idx;}

int main(){
    int N, Q;
    int i;
    scanf("%d%d", &N, &Q);
    for(i = 1; i <= N; ++i)
        scanf("%d", &a[i]);
    for(i = 0; i < Q; ++i){
        scanf("%d%d", &q[i].l, &q[i].r);
        q[i].idx = i;
    }
    block = sqrt(N);
    std::sort(q, q + Q, cmp);
    int curL = q[0].l;
    int curR = q[0].l;
    int num = 1;
    cnt[a[curL]] = 1;
    for(i = 0; i < Q; ++i){
        while(curR < q[i].r){
            ++curR;
            if(cnt[a[curR]] == 0)
                ++num;
            ++cnt[a[curR]];
        }
        while(curR > q[i].r){
            if(cnt[a[curR]] == 1)
                --num;
            --cnt[a[curR]];
            --curR;
        }
        while(curL < q[i].l){
            if(cnt[a[curL]] == 1)
                --num;
            --cnt[a[curL]];
            ++curL;
        }
        while(curL > q[i].l){
            --curL;
            if(cnt[a[curL]] == 0){
                ++num;
            }
            ++cnt[a[curL]];
        }
        q[i].ans = num;
    }
    std::sort(q, q + Q, cmp2);
    for(i = 0; i < Q; ++i)
        printf("%d\n", q[i].ans);
    return 0;
}

Measured memory_bytes: 15372
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>

using namespace std;

int main(void){
    int n, m;

    cin >> n >> m;

    vector<map<int, int>> city(n);
    vector<pair<int, int>> input_hist(m);

    for(int i=0; i<m; i++){
        int p, y;
        cin >> p >> y;

        p--;

        int idx = city[p].size();
        city[p][y] = idx;

        input_hist[i] = pair<int, int>(p, y);
    }

    for(int i=0; i<n; i++){
        int cnt = 0;
        for(auto&& c : city[i]){
            c.second = cnt;
            cnt++;
        }
    }

    for(int i=0; i<m; i++){
        int p = input_hist[i].first;
        int y = input_hist[i].second;

        printf("%06d%06d\n", p+1, city[p][y]+1);
    }
    return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int x = 0, ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == 'I') {
            x++;
        }
        else {
            x--;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    cin >> a >> b;
    
    if (a%2 != b%2)cout << "IMPOSSIBLE" << endl;
    else cout << (a+b)/2 << endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.1415926535
#define MOD 1000000007
 
int main(){
  
  ll N, M;
  cin >> N >> M;
  
  ll H[N];
  for(int i = 0;i < N;i++)  cin >> H[i];
  
  ll A[M], B[M];
  for(int i = 0;i < M;i++)  cin >> A[i] >> B[i];
  
  ll cnt = 0;
  ll ans[N];
  for(int i = 0;i < N;i++)  ans[i] = 0;
  for(int j = 0;j < M;j++){
    if(H[A[j] - 1] >= H[B[j] - 1])  ans[B[j] - 1]++;
    if(H[A[j] - 1] <= H[B[j] - 1])  ans[A[j] - 1]++;
  }
  
  for(int i = 0;i < N;i++)  if(ans[i] == 0)  cnt++;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 6752
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 100010;
const int INF = 2147483600;
const LL Mod = 1e9+7;

int N,A,B; LL f[2][5010][5010],h[2][2][5010],g[5010][5010];

inline void Add(LL &a,LL b){ a=(a+b>=Mod?a+b-Mod:a+b); }

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(),A=read(),B=read(); LL pw2=1;
	for(int i=1;i<=N;i++) pw2=pw2*2%Mod;
	f[1][1][0]=1; f[0][1][1]=1; if(A>B) swap(A,B);
	for(int x=0;x<2;x++)
		for(int i=1;i<B;i++){
			for(int j=0;j<=i;j++){
				if(j>=A) Add(f[x][i+1][0],f[x][i][j]);
				Add(f[x][i+1][j+1],f[x][i][j]);
			} Add(f[x][i+1][0],f[x][i][0]);
		} 
	for(int x=0;x<2;x++) 
		for(int i=1;i<B;i++){
			h[x][1][i]=f[x][i][0];
			for(int j=A;j<=i;j++) Add(h[x][0][i],f[x][i][j]);
		}
	g[0][0]=1;
	for(int i=0;i<N;i++){
		LL g0=0;
		for(int j=1;j<=min(i,A-1);j++) Add(g0,g[i][j]);
		for(int j=0;j<=min(i,A-1);j++) Add(g[i+1][j+1],g[i][j]);
		for(int j=1;j<B&&j+i<=N;j++){
			if(!i&&i+j==N){ Add(g[i+j][0],(h[0][0][j]+h[1][1][j]+h[1][0][j]+h[0][1][j])%Mod); continue; }
			if(!i){ Add(g[i+j][0],(h[0][1][j]+h[1][1][j])%Mod); continue; }
			if(i+j==N){ Add(g[i+j][0],g0*(h[1][0][j]+h[1][1][j])%Mod); continue;}
			Add(g[i+j][0],g0*h[1][1][j]%Mod);
		}
	} for(int i=0;i<A;i++) pw2-=g[N][i]; pw2=pw2%Mod+Mod; pw2%=Mod;
	printf("%lld\n",pw2);
	return 0;
}




Measured memory_bytes: 353740
#include<iostream>
#include<cmath>

int main(){
  int k, a, b;
  std::cin>>k>>a>>b;
  int res = std::ceil(a/k);

  while(res*k <= b){
    if(res*k>=a){
      std::cout<<"OK"<<std::endl;
      break;
    }
    else
      ++res;
  }
  if(res*k > b)
    std::cout<<"NG"<<std::endl;
}


Measured memory_bytes: 3592
#include<stdio.h>
main(){
  int a[100]={0},i,j,smp=0;
  while(1){
    if(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4]) == EOF)break;
    for(i=0;i<5;i++){
      for(j=i+1;j<5;j++){
	if(a[i] > a[j]){
	  smp = a[i];
	  a[i] = a[j];
	  a[j] =smp;
	}
      }
    }
    if(a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3]||a[1]==a[2]&&a[2]==a[3]&&a[3]==a[4]){
      printf("four card\n");
    }
    else if(a[0]==a[1]&&a[2]==a[3]&&a[3]==a[4]||a[0]==a[1]&&a[1]==a[2]&&a[3]==a[4]){
      printf("full house\n");
    }
    else if(a[0]+1==a[1]&&a[1]+1==a[2]&&a[2]+1==a[3]&&a[3]+1==a[4]||a[0]==1&&a[1]==10&&a[2]==11&&a[3]==12&&a[4]==13){
      printf("straight\n");
    }
    else if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]||a[2]==a[3]&&a[3]==a[4]){
      printf("three card\n");
    }
    else if(a[0]==a[1]&&a[2]==a[3]||a[0]==a[1]&&a[3]==a[4]||a[1]==a[2]&&a[3]==a[4]){
      printf("two pair\n");
    }
    else if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]||a[3]==a[4]){
      printf("one pair\n");
    }
    else{
      printf("null\n");
    }
  }
  return 0;
}
    
    

Measured memory_bytes: 580
#入力受け取りの高速化、しなくてもよい
#但し文字列のまま扱うときは注意、例えば . は46として、 # は35として扱われる
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
#ここまでが高速化
h,w=map(int,input().split())
nx,ny=map(int,input().split())
gx,gy=map(int,input().split())
maze=inputs()
#0 based index (0始まり)にする
nx-=1;ny-=1;gx-=1;gy-=1
from collections import deque
#dqが徒歩、2が魔法での移動を入れる
dq=deque([(nx,ny)])
dq2=deque([])
#かかるコストを保存しておく
T=[[float('inf')]*w for  a in range(h)]
#初期値は0で、スタート地点に保存
T[nx][ny]=0
#徒歩でのx,yの差分
moves=((1,0),(-1,0),(0,1),(0,-1))
from itertools import product as pr
#魔法での移動の差分、tuple( (i,j) |-2<=i,j<=2かつ(i,j)!=(0,0)  )と等価
Mmoves=tuple(i for i in pr((-2,-1,0,1,2),repeat=2)if i!=(0,0) )

while dq:
    #先に徒歩で行けるだけ行きたいので、徒歩を使い切るまでは魔法で行った地点たちに手を出さない
    while dq:
        x,y=dq.popleft()
        for i,j in moves:
            nex,ney=x+i,y+j
            #盤面の外や壁にぶつかるのは除外
            if not(0<=nex<h and 0<=ney<w) or maze[nex][ney]==35:continue
            if T[x][y]<T[nex][ney]:
                #コストを更新できるなら改めて捜査
                T[nex][ney]=T[x][y]
                dq.append((nex,ney))
        for i,j in Mmoves:
            nex,ney=x+i,y+j
            if not(0<=nex<h and 0<=ney<w) or maze[nex][ney]==35:continue
            if T[x][y]+1<T[nex][ney]:
                T[nex][ney]=T[x][y]+1
                dq2.append((nex,ney))
    #徒歩で行ける地点を使い切ったので、今度は魔法で行ける地点を捜査
    dq,dq2=dq2,dq
if T[gx][gy]==float('inf'):print(-1)
else:print(T[gx][gy])

Measured memory_bytes: 99648
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;


void main() {
	int n = to!int(readln().strip());
	int p, max;
	p = 1;
	for(int i; i < n; ++i){
		auto s = readln().strip().split();
		auto a = to!int(s[0]);
		auto v = to!int(s[1]);
		if(v > max){
			p = a;
			max = v;
		}else if(v == max) {
			p = min(a,p);
		}
	}
	writefln("%d %d", p, max);
}

Measured memory_bytes: 1064
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    boolean[] rate = new boolean[8];
    int maxCount = 0;
    int n = sc.nextInt();
    for(int i = 0; i < n; i++){
      int a = sc.nextInt();
      if(a >= 3200){
        maxCount++;
      }else{
        rate[a/400] = true;
      }
    }
    int min = 0;
    for(int i = 0; i < 8; i++){
      if(rate[i]) min++;
    }
    if(min == 0){
      min = 1;
      maxCount--;
    }
    System.out.println(min + " " + (min + maxCount));
  }
}


Measured memory_bytes: 23764
#include <stdio.h>

int main(){

  int a,b,remain,k;

  scanf("%d %d",&a,&b);

  if(a<b){
    k=a;
    a=b;
    b=k;
  }


  remain=a%b;
  while(remain!=0){
    a=b;
    b=remain;
    remain=a%b;
  }

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

  return 0;
}

Measured memory_bytes: 592
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    bool F = true;
    for(int i = 0; i < S.size(); i++){
        if(i % 2 == 0){
            if(!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')){
                F = false;
                break;
            }
        }else{
            if(!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')){
                F = false;
                break;
            }
        }
    }

    if(F){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define INF 1000000000
#define loop(i,a,b) for(int i=a;i<b;i++)
int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,fix=1000000000000000000;
    cin>>n;
    ll a[n],mul=1;
    int flag=0,big=0;
    loop(i,0,n)
    {
        cin>>a[i];
        if(a[i]==0)
            flag=1;
    }
    if(flag>0)
        cout<<0<<endl;
    else
    {
        mul=1;
        loop(i,0,n)
        {
            if(a[i]<=1000000000000000000/mul)
            {
                mul*=a[i];
            }
            else
            {
                cout<<-1<<endl;
                return 0;
            }
        }
        cout<<mul<<endl;
    }

    return 0;
}


Measured memory_bytes: 4412
#include<stdio.h>

int main(void){
       int x1,x2,x3,x4,x5;
       scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);

       if(x1==0)printf("1");
       if(x2==0)printf("2");
       if(x3==0)printf("3");
       if(x4==0)printf("4");
       if(x5==0)printf("5");
       return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{

  int a, p;
  cin >> a >> p;
  pr((a * 3 + p) / 2);
  return 0;
}


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

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

int main()
{
	int n;
	long long k;
	while(cin >> n >> k && n){
		k--;
		if( k >= (1ll<<(n/2)) || n % 2 == 1 ){
			cout << "No" << endl;
			cout << endl;
			continue;
		}
		int table[64][64];
		memset(table,-1,sizeof(table));
		//一行決めると一意に定まる
		for(int i = 0 ; i < n ; i++)
			table[0][i] = ( k >> ((n-i-1)/2) & 1 );
		
		for(int i = 0 ; i < n-1 ; i++){
			for(int j = 0 ; j < n ; j++){
				int cnt = 0;
				for(int d = 0 ; d < 4 ; d++){
					int tx = j + dx[d],ty = i + dy[d];
					if( tx < 0 || tx >= n || ty < 0 || ty >= n ) continue;
					if( table[ty][tx] == table[i][j] ) cnt++;
				}
				if( cnt == 2 ) table[i+1][j] = !table[i][j];
				else table[i+1][j] = table[i][j];
			}
		}
		for(int y = 0 ; y < n ; y++){
			for(int x = 0 ; x < n ; x++){
				cout << (char)(table[y][x]?'E':'.');
			}
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1184
import math

X=int(input())

def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    # nの平方根まで計算する
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True
i=X
while True:
    if isPrime(i):
        break
    i=i+1
print(i)

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	total := 0
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
		total += as[i]
	}

	cnt := 0
	x := float64(total) * (1 / (4 * float64(m)))
	for i := 0; i < n; i++ {
		if x <= float64(as[i]) {
			cnt++
		}
	}

	if m <= cnt {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



int calc(int n,int a[]){
	int res=0,t=0;
	t+=a[0];
	for(int i=1;i<n;i++)t+=1-a[i];
	res=max(res,t);
	t=0;
	for(int i=0;i<n-1;i++)t+=1-a[i];
	t+=a[n-1];
	res=max(res,t);

	for(int i=1;i<n-1;i++){
		t=0;
		t+=a[0];
		for(int j=1;j<i;j++)t+=1-a[j];
		t+=a[i];
		for(int j=i+1;j<n-1;j++)t+=1-a[j];
		t+=a[n-1];
		res=max(res,t);
	}
	return res;
}
int main(){
	int m,n,a[100];
	int ans=0;
	cin>>m>>n;
	rep(i,m){
		rep(j,n)cin>>a[j];
		if(i)rep(j,n)a[j]^=1;
		ans+=calc(n,a);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int a,b,t;
int main(){
	cin>>a>>b>>t;
	int ans = 0;
	for(int i=a;i<=t;i+=a){
		ans+=b;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,cnt=0; cin>>a>>b;
  for(int i=a; i<=b; i++){
    if(i/10000==i%10&&i/1000%10==i%100/10) cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <functional>

int main() {
	int n;
	std::cin >> n;
	if(n==3 || n==5 || n==7){
		std::cout << "YES";
	}else{
		std::cout << "NO";
	}
	std::cout << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,i,j,k,f;
  vector <int> sm;
  for(i=1;i<60000/7+1;i++){
    f=0;
    for(j=0;j<sm.size();j++){
      if((7*i-1)%sm[j]==0) f = 1;  
    }
    if(f==0) sm.push_back(7*i-1);
    f=0;
    for(j=0;j<sm.size();j++){
      if((7*i+1)%sm[j]==0) f = 1;  
    }
    if(f==0) sm.push_back(7*i+1);
  }
  cin >> n;
  while(n!=1){
    cout << n << ":";
    f=0;
    for(i=0;i<sm.size();i++){
      if(n%sm[i]==0) {
	cout << " " << sm[i];
	f=1;
      }
    }
    if(f==0) cout << " " << n;
    cout << endl;
    cin >> n;
  }
  return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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 dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

const int inf=100000000;



int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    cin>>s;
    int cnt=0;
    int ans=0;
    int diff=0;
    int n=s.size();

    REP(i,n)
    {
        cnt+=s[i]-'0';
    }
    diff=(s[0]-'0')-1+(n-1)*9;
    ans=max(cnt,diff);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine().split("")[0]);
        String[] nums = sc.nextLine().split(" ");

        int max = 0;
        int cnt = 0;
        for (String num : nums) {
            int h = Integer.parseInt(num);
            if (max <= h) {
                cnt++;
                max = h;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 22612