akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        long cut = 998244353;

        int[] l_array = new int[K];
        int[] r_array = new int[K];

        for(int i = 0; i < K; i++) {
            String[] input_array = br.readLine().split(" ");
            l_array[i] = Integer.parseInt(input_array[0]);
            r_array[i] = Integer.parseInt(input_array[1]);
        }
        
        long[] dp = new long[N + 10];
        dp[1] = 1;

        long[] sum_array = new long[N + 10];
        sum_array[1] = 1;

        for(int i = 2; i <= N; i++) {    
            
            for(int j = 0; j < K; j++) {
                int max_index = i - l_array[j];
                int min_index = i - r_array[j];

                if(min_index <= 0 && max_index <= 0) {
                    continue;
                } else if(min_index <= 0 && max_index > 0) {
                    min_index = 1;
                }

                long sum = sum_array[max_index] - sum_array[min_index - 1];

                if(sum < 0) sum += cut;

                dp[i] += sum;
                dp[i] %= cut;
            }

            sum_array[i] = (sum_array[i-1] + dp[i]) % cut;

        }
        
        pw.println(dp[N]);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 37012
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         int N = int.Parse(ReadLine());
         var current = new List<string>();
         current.Add("a");
         for(int i = 2; i <= N; i++){
             var next = new List<string>();
             foreach(var item in current){
                 char max = item.Max();
                 if(max < 'z') max++;
                 for(char chara = 'a'; chara <= max; chara++) next.Add((item + chara));
             }
             current = next;
         }
         foreach (var item in current)
         {
             WriteLine(item);
         }
      }
   }
}

Measured memory_bytes: 23504
import java.io.*;
import java.util.*;
import java.lang.*;

class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        int [] count = new int[26];
        
        while(scan.hasNext()){
            String line  = scan.next();
            
            for(int i = 0; i < line.length(); ++i){
                if(Character.isLowerCase(line.charAt(i))){
                    ++count[line.charAt(i) - 'a'];
                }
                
                else if(Character.isUpperCase(line.charAt(i))){
                    ++count[line.charAt(i) - 'A'];
                }
            }
        }
        
        for(int i = 0; i < count.length; ++i){
            System.out.println((char)('a' + i) + " : " + count[i]);
        }
    }
}


Measured memory_bytes: 26128
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		
		int input1 = input.nextInt();
		int input2 = input.nextInt();
	 
		if ((input1 + input2) % 2 == 0)
			System.out.print((input1 + input2) / 2);
		else
			System.out.print("IMPOSSIBLE");
		
		
		input.close();

	}

}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LoopMAX 20

int main() {
  int N;
  cin >> N;
  
  vector<int> Hi;
   
  rep(i,N){
    int tmpHi = 0;
    cin >> tmpHi;
    Hi.push_back(tmpHi);
  }
  
  int ans = 0;
  int tmp_ans = 0;
  
  rep(i,N -1){  
    if(Hi.at(i) >= Hi.at(i + 1)){
      tmp_ans++;
    }else{
      tmp_ans = 0;
    }
    ans = max(ans,tmp_ans);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
string s[1005];
int dp[1005][1005];
int n,m;
int main() {
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; i++) cin >> s[i];
	dp[0][0]=1;
	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			if(i+j==0) continue;
			if(s[i][j]=='#') continue;
			if(i>0) dp[i][j]+=dp[i-1][j];
			if(j>0) dp[i][j]+=dp[i][j-1];
			dp[i][j]%=(int)(1e9+7);
		}
	}
	printf("%d\n",dp[n-1][m-1]);
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long A, long long B, long long C, long long K) {
  K++;
  while(K--){
    cerr << A << " " << B << " " << C << endl;
    if(B>=C){
      C*=2;
      continue;
    }
    if(A>=B){
      B*=2;
      continue;
    }
    cout << "Yes"<<endl;
    return;
  }
  cout << "No"<<endl;
}

signed main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  long long K;
  scanf("%lld", &K);
  solve(A, B, C, K);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const int MAX=1e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> V(N+1),W(N+1);
    for (int i=1;i<=N;++i) cin >> V[i] >> W[i];
    int half=1<<10;
    vector<vector<int>> dp(half,vector<int>(MAX,0));
    for (int i=1;i<min(N+1,half);++i){
        int p=i/2;
        for (int j=0;j<MAX;++j){
            dp[i][j]=max(dp[i][j],dp[p][j]);
            if (j+W[i]<MAX) dp[i][j+W[i]]=max(dp[i][j+W[i]],dp[p][j]+V[i]);
        }
        for (int j=0;j<MAX-1;++j) dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
    }
    int Q; cin >> Q;
    for (;Q--;){
        int v,L; cin >> v >> L;
        if (v<half){
            cout << dp[v][L] << '\n';
            continue;
        }
        vector<int> pv,pw;
        for (;v>=half;v>>=1){
            pv.emplace_back(V[v]);
            pw.emplace_back(W[v]);
        }
        int n=pv.size(),ans=0;
        for (int mask=0;mask<(1<<n);++mask){
            int sv=0,sw=0;
            for (int i=0;i<n;++i){
                if (mask&1<<i){
                    sv+=pv[i]; sw+=pw[i];
                }
            }
            if (sw>L) continue;
            ans=max(ans,sv+dp[v][L-sw]);
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 407064
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> N >> K;
  ll h[N];
  ans = 0;
  rep(i, N){
    cin>>h[i];
    if (h[i]>= K) ans++;
  }
  cout << ans << endl;
  
  
   




}


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

int main()

{
	int n, k;
	cin >> n >> k;
	
	int arr[n+1];
	
	for(int i=0; i<n; i++)
		cin>>arr[i];
		
	sort(arr, arr+n);
	
	int sum=0;
	for(int i=0; i<k; i++){
		sum = sum + arr[i];
	}
	
	cout<< sum <<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

const int MAXN = 110;

int N;
ll W;
ll wm;
pair <int, int> p[MAXN];

vector <int> v[4];

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        cin >> p[i].first >> p[i].second;
    }

    wm = p[0].first;
    for (int i = 0; i < N; i++)
    {
        p[i].first -= wm;
        v[p[i].first].push_back(p[i].second);
    }

    int pt = 1;
    for (int i = 0; i < 4; i++)
    {
        sort (v[i].begin(), v[i].end());
        reverse (v[i].begin(), v[i].end());
        pt *= v[i].size() + 1;
    }

    ll ans = 0;
    for (int z = 0; z < pt; z++)
    {
        int tz = z;
        ll ttot = W;
        ll bval = 0;
        for (int i = 0; i < 4; i++)
        {
            int ng = tz % (v[i].size() + 1);
            ttot -= ng * (wm + i);
            for (int j = 0; j < ng; j++)
                bval += v[i][j];

            tz /= (v[i].size() + 1);
        }
        if (ttot >= 0) ans = max (ans, bval);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
struct amida{
	int h,A,B;
};
int main(){
	int n,m,a;
	while(cin>>n>>m>>a,n+m+a!=0){
		vector<amida>kuzi;
		int now=a;
		for(int i=0;i<m;i++){
			int x,y,z;
			cin>>x>>y>>z;
			amida tmp;
			tmp.h=x,tmp.A=y,tmp.B=z;
			kuzi.push_back(tmp);
		}
		/*for(int i=0;i<kuzi.size();i++){
			for(int j=i;j<kuzi.size();j++){
				if(kuzi[i].h<kuzi[j].h)swap(kuzi[i],kuzi[j]);
			}	
		}*/
		for(int i=1001;i>=1;i--){
			for(int j=0;j<kuzi.size();j++){
				if(kuzi[j].A==now&&kuzi[j].h==i){
					now=kuzi[j].B;
					break;
				}
				if(kuzi[j].B==now&&kuzi[j].h==i){
					now=kuzi[j].A;
					break;
				}
			}
		}
		cout<<now<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <algorithm>
#include <numeric>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int n, d, x;
  cin >> n >> d >> x;
  vector<vector<int>> P(d,vector<int>(n));

  for(int i = 0; i < d; ++i)
    for(int j = 0; j < n; ++j)
      cin >> P[i][j];

  for(int i = 0; i < d-1; ++i){
    vector<int> dp(x+1,0);
    iota(dp.begin(), dp.end(), 0);
    for(int j = 0; j <= x; ++j){
      for(int k = 0; k < n; ++k){
        int j_ = j+P[i][k];
        if(j_ > x) continue;
        dp[j_] = max(dp[j_],dp[j]+P[i+1][k]);
      }
    }
    x = *max_element(dp.begin(), dp.end());
  }
  cout << x << endl;
}



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



int main(){
	int n, k;
	cin >> n >> k;
	int ans = 0;
	vector<int> x(n);
	for(int i = 0; i < n; i++)
	{
		cin >> x[i];
		x[i] = min(x[i], abs(x[i]-k));
		ans += x[i]*2;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・直径の長さをdとする。だいたい、半径より下の長さは存在できない
・だいたいd/2より上は任意に足せる。ただし中心は1組のみ
"""

N,*A = map(int,read().split())

def test(A):
    D = max(A)
    r = (D+1)//2
    counter = [0] * (D+1)
    for x in A:
        counter[x] += 1
    if (D&1) and (counter[r] != 2):
        return False
    if (not (D&1)) and (counter[r] != 1):
        return False
    if any(x < r for x in A):
        return False
    if any(counter[x] <= 1 for x in range(r+1,D+1)):
        return False
    return True

answer = 'Possible' if test(A) else 'Impossible'

print(answer)

Measured memory_bytes: 3064
//
// Created by TakahiroYamaji on 2020/08/03.
//
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int N;
string S;
int main(){
    cin >> N >> S;
    int a = 0, b = 0;
    for (int i=0;i<N;i++){
        if (S[i] == 'R') a++;
    }
    int res = max(a,b);
    for (int i=0;i<N;i++){
        if (S[i] == 'R') --a;
        else ++b;
        res = std::min(res, max(a, b));

    }
    cout << res << endl;

}



Measured memory_bytes: 3460
/*
    BY - master_coder ( Tanu kumar )
    college - AIT
    Problem - contest ( div 3 )
*/
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define rep(i,a,n) for( int i = a ; i < n ; i++ )
#define prep( i, a , n ) for ( int i = a ; i>= n ; i--)
#define   pr pair<int,int>
const int N = 1e5 + 5 , M=N,inf=(int)1e9;
const int mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
ll ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
vector < int > h[N];
void solve(){

   int x ;
   cin >> x ;
   if( x == 7 || x == 5 || x == 3) cout <<"YES";
   else cout << "NO";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}
/*
    ---------------- lemmas-----------------------------------
   1)
   2)
   3)

*/


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	ll a, b, n; scanf("%lld%lld%lld", &a, &b, &n);
	printf("%lld\n", a * min(n, b-1) / b);
}


Measured memory_bytes: 3824
import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import accumulate
def main():
    N = int( input())
    L = list( map( int, input().split()))
    d = defaultdict( int)
    ans = 0
    
    for l in L:
        d[l] += 1
    L.sort()
    R = list( set(L))
    R.sort()
    for e in d:
        if d[e] >= 3:
            ans += d[e]*(d[e]-1)*(d[e]-2)//6
        if d[e] >= 2:
            cnt = 0
            t = d[e]*(d[e]-1)//2
            for l in R:
                if l == e:
                    continue
                if l < 2*e:
                    cnt += t*d[l]

            ans += cnt
    T = [0]*(10**4)
    M = len(R)
    Z = [0]*(10**4)

    for i in range(M):
        for j in range(i+1, M):
            e = R[i]
            f = R[j]
            t = d[e]*d[f]
            T[ abs(e-f)+1] += t
            T[ e+f] -= t
            if abs(e-f) < e:
                Z[e] += t
            if abs(e-f) < f:
                Z[f] += t
    S = list( accumulate(T))
    a = 0

    for e in d:
        if S[e] > 0:
            a += (S[e] - Z[e])*d[e]

    print(ans+a//3)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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 main(){

    int a,b,c,d,e,f; cin >> a >> b >> c >> d >> e >> f;

    vector<int> water,sugar;
    int i = 0, j;
    while(i*a*100 <= f){
        j = 0;
        while(i*a*100 + j*b*100 <= f){
            int o = i*a*100 + j*b*100;
            if(i+j != 0) {
                water.push_back(o);
            }
            j++;
        }
        i++;
    }
    int p = 0,q;
    while(c*p <= f){
        q = 0;
        while(c*p + d*q <= f){
            int o = c*p + d*q;
            sugar.push_back(o);
            q++;
        }
        p++;
    }
    int wa_size = water.size();
    int su_size = sugar.size();
    int ans_sum = 0;
    int ans_sug = 0;
    ld dens = -1.0;
    rep(x,wa_size)rep(y,su_size){

            int sum = water.at(x)+sugar.at(y);
            if(sum <= f && sugar.at(y) <= water.at(x)*e/100){
                if(sugar.at(y)/double(sum) > dens){
                    dens = sugar.at(y)/double(sum);
                    ans_sum = sum;
                    ans_sug = sugar.at(y);
                } 
            }
    }
    cout << ans_sum sp ans_sug << endl;
    return 0;
}


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

int main() {
    long long i, j, n;
    long long a[9];
    long long ans[9] = {0};
    for(i = 0; i < 9; i++){
        cin >> a[i];
    }
    cin >> n;
    long long b[n];
    for(i = 0; i < n; i++){
        cin >> b[i];
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < 9; j++){
            if(b[i] == a[j]){
                ans[j] = 1;
                break;
            }
        }
    }
    if((ans[1]&&ans[2]&&ans[0])||(ans[4]&&ans[5]&&ans[3])||(ans[7]&&ans[8]&&ans[6])||(ans[0]&&ans[3]&&ans[6])||(ans[1]&&ans[4]&&ans[7])||(ans[2]&&ans[5]&&ans[8])||(ans[0]&&ans[4]&&ans[8])||(ans[2]&&ans[4]&&ans[6])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll fac[MAXn],inv[MAXn];
ll fpow(ll a,ll b){
    ll ret = 1;
    while (b) {
        if (b&1) ret = (ret * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return ret;
}
void init(){
    fac[0] = inv[0] = 1;
    REP1 (i,MAXn-1) fac[i] = (fac[i-1] * i) % MOD;
    REP1 (i,MAXn-1) inv[i] = fpow(fac[i],MOD-2);
}
ll C(ll a,ll b){
    if (b == 0) return 1;
    return fac[a] * inv[b] % MOD * inv[a-b] % MOD;
}
int main(){
    IOS();
    init();
    ll n,m,k;
    cin >> n >> m >> k;
    ll ans = 0;
    REP1 (i,n-1) ans = (ans + (n-i) * i % MOD * m % MOD * m % MOD) % MOD;
    REP1 (i,m-1) ans = (ans + (m-i) * i % MOD * n % MOD * n % MOD) % MOD;
    ans = (ans * C(n*m-2,k-2)) % MOD;
    assert(ans > 0);
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vei vector<int>
#define vep vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++){cout<<a[i]<<" ";cout<<endl;}}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1LL; while (b > 0) {if (b & 1LL) {c = a * c%mod;}a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}



bool solve() {
	int n; cin >> n;
	int w[n]; int sum[n+1];
	sum[0] = 0;
	REP (i,n) {cin >> w[i]; sum[i+1] = sum[i] + w[i];}
	sort(w,w+n);
	int mi = INF, ans = 0;
	REP (i,n+1) {
		int tmp = abs(sum[n] - sum[i] * 2);
		if (mi > tmp) {mi = tmp;}
	}
	cout << mi << endl;
}

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

	solve();
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n,q=MI()
    #ソース　https://juppy.hatenablog.com/entry/2018/11/17/蟻本_python_Binary_Indexed_Tree_競技プログラミング
    #A1 ... AnのBIT(1-indexed)
    BIT = [0]*(n+1)
    #idxの一番下のbit
    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum
    
    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= n:
            BIT[idx] += x
            idx += idx&(-idx)
        return
    lis=LI()
    for i in range(n):
        BIT_update(i+1,lis[i])
    for i in range(q):
        a,b,c=MI()
        if a==0:
            BIT_update(b+1,c)
        else:
            ans=BIT_query(c)-BIT_query(b)
            print(ans)



        
        
        
        
        
    
if __name__=="__main__":
    main()



Measured memory_bytes: 69296
Q, H, S, D = map(int, input().split())
N = int(input())

cost = N//2

price = min(D*cost, S*2*cost, H*4*cost, Q*8*cost)
if(N%2 == 0):
    print(price)
else:
    price += min(S, 2*H, 4*Q)
    print(price)


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	char text1[3] = {0},text2[3] = {0};
	for (int i = 0; i < 3; i++){
		scanf(" %c",&text1[i]);
	}
	
	for (int i = 0; i < 3; i++){
		scanf(" %c",&text2[i]);
	}
	for (int i = 0;i < 3; i++)
	{
		if (text1[i] != text2[2 - i]){
			printf("NO\n");
			return 0;
		}	
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
a = int(input())
ans = 0
i = 1
while i <= a:
    if i%15 == 0:
        i += 1
        continue
    elif i%3 == 0:
        i += 1
        continue
    elif i%5 == 0:
        i += 1
        continue
    ans += i
    i += 1
    
print(ans)


Measured memory_bytes: 9140
PROGRAM piyo
      IMPLICIT NONE
      integer :: n,m,p(10),k(10),sNum(10,10),ans=0
      logical :: s(10,10) = .false.,switch(10)
      integer :: i,j
      
      read*,n,m
      do i = 1,m
        read(fmt='(i2)',advance='no',unit=5) k(i)
        read*,sNum(i,1:k(i))
      end do
      read*,p(1:m)
      
      do i = 1,m
        do j = 1,k(i)
          s(i,sNum(i,j)) = .true.
        end do
      end do
 ! do i = 1,m
 !   print*,s(i,:)
 ! end do
      !s(n,k(i))
      
      
      outer:do i = 0,2**n-1
        switch = .false.
        do j = 1,n
          switch(j) = btest(i,j-1)
        end do
        
        do j = 1,m
          if(p(j)/= mod( count(switch(1:n).and.s(j,1:n)),2 ))then
            cycle outer
          end if
        end do
        ans = ans + 1
      end do outer
      
      print*,ans
      
 !debugg
  !    print*,n,m
  !    do i = 1,m
  !      print*,k(i),sNum(i,1:k(i))
  !    end do
  !    print*,p(1:m)
      
      END PROGRAM

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


int main()
{
    int a,b; cin >> a >> b;
    if(a >= 10 || b >= 10) cout << -1 << endl;
    else cout << a*b << endl;
}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

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

ll a, b, c;

int main() {
    cin >> a >> b >> c;

    if (a + b >= c) cout << "No" << endl;
    else {
        ll tmp = a*a + b*b + c*c -2*(a*b + a*c + b*c);
        if (tmp > 0) cout << "Yes" << endl;
        else cout << "No" << endl; 
    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;



int main(){
    INIT;
    std::set<int> st;
    int n;
    cin >> n;
    REP(i,n) {
        int a; cin >> a;
        if(st.find(a) != st.end()) st.erase(a);
        else st.insert(a);
    }
    cout << st.size();
}

Measured memory_bytes: 4992
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int a[100][100];
int b[100];
vector <int> v[100];

vector <int> merge(vector <int> &v, vector <int> &w) {
    int i;
    vector <int> z = v;
    
    for (i = 0; i < w.size(); i++) {
        if (i < v.size()) {
            z[i] = max(z[i], w[i]);
        } else {
            z.push_back(w[i]);
        }
    }
    
    return z;
}

vector <int> dfs(int x, int y) {
    int f = 0, i;
    vector <int> w;
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) {
            f = 1;
            continue;
        }
        
        vector <int> z = dfs(v[x][i], x);
        w = merge(w, z);
    }
    
    if (v[x].size() != f) w.insert(w.begin(), v[x].size() - f);
    
    return w;
}

long long calc(int x, int y) {
    int i;
    long long ans = 2;
    vector <int> z1 = dfs(x, y);
    vector <int> z2 = dfs(y, x);
    vector <int> z = merge(z1, z2);
    
    for (i = 0; i < z.size(); i++) ans *= z[i];
    
    return ans;
}

long long calc2(int x) {
    int i;
    long long ans = 1;
    vector <int> z = dfs(x, -1);
    
    for (i = 0; i < z.size(); i++) ans *= z[i];
    
    return ans;
}

int main() {
    int n, i, j, k;
    long long ans1, ans2;
    vector <int> w;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (i == j) {
                a[i][j] = 0;
            } else {
                a[i][j] = 1e9;
            }
        }
    }
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        a[x][y] = a[y][x] = 1;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            for (k = 0; k < n; k++) {
                a[j][k] = min(a[j][k], a[j][i] + a[i][k]);
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) b[i] = max(b[i], a[i][j]);
    }
    
    w.push_back(0);
    for (i = 1; i < n; i++) {
        if (b[i] < b[w[0]]) {
            w.clear();
            w.push_back(i);
        } else if (b[i] == b[w[0]]) {
            w.push_back(i);
        }
    }
    
    if (w.size() == 1) {
        ans1 = b[w[0]] + 1;
        ans2 = calc2(w[0]);
        
        for (i = 0; i < v[w[0]].size(); i++) ans2 = min(ans2, calc(w[0], v[w[0]][i]));
    } else {
        ans1 = b[w[0]];
        ans2 = calc(w[0], w[1]);
    }
    
    printf("%lld %lld\n", ans1, ans2);
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <iostream>
//#include <string>
//#include <algorithm>
//#include <stdio>
using namespace std;
typedef long long ll;
const int maxn = (int)1e3 +10;

int main()
{

    ll a, b;
    cin>>a>>b;
    if((a+b)%2 == 0)
        cout<<(a+b)/2;
    else
        cout<<"IMPOSSIBLE"<<endl;

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0;i < n ;i++)cin >> a.at(i);

vector<int> ans(n);

for (int i = 0; i < n; i++)ans.at(a.at(i)-1) = i + 1;
for (int i = 0; i < n; i++)cout << ans[i] << endl;


    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <math.h>

int main(void)
{
	double y;
	double v;
	double f;
	double t;
	int i;
	
	while (scanf("%lf", &v) != EOF){
		t = v / 9.8;
		y = 4.9 * t * t;
		f = (y + 5) / 5;
		
		i = (int)ceil(f);
		printf("%d\n", i);
	}
	
	return (0);
}

Measured memory_bytes: 632
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, long long R){
    if (N >= 10) cout << R << '\n';
    else {
        long long  ans;
        ans = R + 100 * (10 - N);
        cout << ans << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long R;
    scanf("%lld",&R);
    solve(N, R);
    return 0;
}


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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x>a.x;
        return y<a.y;
    }
};


vector<int> v[11111];
vector<int> v1;
//bitset<4001000> b;
int i,n,m,k,a,d,b,c;
int e;
long long o[211112];
int l[11111];
int j[11131];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
int px[10]={-1,1,1,-1,1,1,-1,-1},py[10]={1,1,-1,-1,1,-1,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> se[33],s1;

//priority_queue<P> q[2];
queue<int> q;
string r,r1;

//char r1[110],r[331];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

bool as(P a,P b)
{
    //if(a.x!=b.x)
    return a.x<b.x;

}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

long long f(long long x,long long y)
{
    long long p=1;
    for(;y;x*=x,x%=mod,y/=2)
    if(y%2) p*=x,p%=mod;
    return p;
}

long long g(int n,int m)
{
    long long x=f(z*b%mod,n)*f(z*c%mod,m)%mod;
    x=x*o[n+m]%mod*f(o[n],mod-2)%mod*f(o[m],mod-2)%mod;
    return x;
}

int main()
{
    z=f(100,mod-2);
    scanf("%d %d %d %d",&a,&b,&c,&d);
    o[0]=1;
    for(int t=1;t<=211100;t++)
        o[t]=o[t-1]*t%mod;
    if(b==0||c==0)
    {
        b=max(b,c);
        printf("%lld",a*100%mod*f(b,mod-2)%mod);
        return 0;
    }
    z=f(b+c,mod-2);
    for(int t=0;t<a;t++)
        x+=(g(t,a-1)*(z*c%mod)%mod+g(a-1,t)*(z*b%mod)%mod)%mod*((a+t)*100%mod*f(b+c,mod-2)%mod)%mod,x%=mod;
    printf("%lld",x);
}




Measured memory_bytes: 2176
use std::io;
use std::io::Read;

fn main(){
    let mut stdin = io::stdin();
    let mut lines_str = String::new();
    let _ = stdin.read_to_string(&mut lines_str);
    let lines_vec = lines_str.lines().collect::<Vec<&str>>();
    let n :usize = lines_vec[0].trim().parse().unwrap();
    let x_vec = lines_vec[1].trim().chars().collect::<Vec<char>>();

    // compute popcount(X)
    let mut popcount_x = 0;
    for &c in &x_vec {
        if c == '1' {
            popcount_x += 1;
        }
    }
    let popcount_x = popcount_x;

    // compute X % (popcount(X)+1) by DP
    let mut x_mod_pplus1 = 0;
    for &c in &x_vec {
        if c == '0' {
            x_mod_pplus1 = (2 * x_mod_pplus1) % (popcount_x + 1);
        } else if c == '1' {
            x_mod_pplus1 = (2 * x_mod_pplus1 + 1) % (popcount_x + 1);
        }
    }
    let x_mod_pplus1 = x_mod_pplus1;

    // compute X % (popcount(X)-1) by DP
    // only if popcount(X) is larger than 1
    let mut x_mod_pminus1 = 0;
    if popcount_x >= 2 {
        for &c in &x_vec {
            if c == '0' {
                x_mod_pminus1 = (2 * x_mod_pminus1) % (popcount_x - 1);
            } else if c == '1' {
                x_mod_pminus1 = (2 * x_mod_pminus1 + 1) % (popcount_x - 1);
            }
        }
    }
    let x_mod_pminus1 = x_mod_pminus1;
    
    // precompute 2^k mod popcount_x +- 1
    let mut diff_mod_pplus1 :Vec<u64> = vec![0;n];
    diff_mod_pplus1[n-1] = 1 % (popcount_x + 1);
    for j in 1..n {
        diff_mod_pplus1[n-1-j] = (2 * diff_mod_pplus1[n-j]) % (popcount_x + 1);
    }
    let diff_mod_pplus1 = diff_mod_pplus1;
    let mut diff_mod_pminus1 :Vec<u64> = vec![0;n];
    if popcount_x >= 2 {
        diff_mod_pminus1[n-1] = 1 % (popcount_x - 1);
        for j in 1..n {
            diff_mod_pminus1[n-1-j] = (2 * diff_mod_pminus1[n-j]) % (popcount_x - 1);
        }
    }
    let diff_mod_pminus1 = diff_mod_pminus1;

    for i in 0..n {
        if x_vec[i] == '0' {
            //xi is not 0
            let xi_mod_pplus1 = (x_mod_pplus1 + diff_mod_pplus1[i]) % (popcount_x + 1);
            println!("{}", 1 + f(xi_mod_pplus1));
        } else if x_vec[i] == '1' {
            if popcount_x == 1 {
                println!("0");
                continue;
            }
            //xi is not 0
            let xi_mod_pminus1 = (popcount_x - 1 + x_mod_pminus1 - diff_mod_pminus1[i]) % (popcount_x - 1);
            println!("{}", 1 + f(xi_mod_pminus1));
        }
    }
}

fn popcount(n :u64) -> u64 {
    let mut result = 0;
    let mut m = n;
    while m != 0 {
        if m & 1 != 0 {
            result = result + 1;
        }
        m = m / 2;
    }
    return result;
}

fn f(n :u64) -> u64 {
    if n == 0 {
        return 0;
    } else {
        return 1 + f(n % popcount(n));
    }
}

Measured memory_bytes: 6084
a,b = map(int, input().split())
tried = (a + b)//3
p = 10**9 +7

if a < tried or b < tried or (a+b)%3 != 0:
    print(0)
    quit()
one = int((2 * a -  b)/3)
n = tried
r = min(one, tried-one)
n_fac = 1
r_fac = 1
n_r_fac = 1

for i in range(2,n+1):
    n_fac *= i
    n_fac %= p
for i in range(2,r+1):
    r_fac *= i
    r_fac %= p
for i in range(2,n-r+1):
    n_r_fac *= i
    n_r_fac %= p
r_fac_inverse = pow(r_fac, p-2, p)
n_r_fac_inverse = pow(n_r_fac, p-2, p)

print((n_fac * r_fac_inverse * n_r_fac_inverse)%p)


Measured memory_bytes: 3064
#include <stdio.h>

char input[100004];

int isok(char prev,char now,int nowisleft) {
	if(prev==now)return 0;
	if(nowisleft) {
		if(prev=='U' || prev=='D') {
			if(now=='R')return 0;
		} else if(prev=='L')return 0;
	} else {
		if(prev=='U' || prev=='D') {
			if(now=='L')return 0;
		} else if(prev=='R')return 0;
	}
	return 1;
}

int main(void) {
	int data_num,cur_data;
	int i;
	int isyes;
	scanf("%d",&data_num);
	for(cur_data=0;cur_data<data_num;cur_data++) {
		scanf("%s",input);
		isyes=1;
		for(i=1;input[i];i++) {
			if(!isok(input[i-1],input[i],i%2)) {
				isyes=0;
				break;
			}
		}
		if(!isyes) {
			isyes=1;
			for(i=1;input[i];i++) {
				if(!isok(input[i-1],input[i],!(i%2))) {
					isyes=0;
					break;
				}
			}
		}
		puts(isyes?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String a = in.next();
		int ct = 0;
		for (int i = 0; i < a.length(); i++) {
			if (a.charAt(i) == '2') {
				++ct;
			}
		}
		out.println(ct);
		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;

int main(void) {
    ll a, b;
    cin >> a >> b;
    ll mina = static_cast<ll>(a / 0.08);
    ll minb = static_cast<ll>(b / 0.1);
    ll maxa = static_cast<ll>((a + 1) / 0.08);
    ll maxb = static_cast<ll>((b + 1) / 0.1);
    ll ans = -1;
    ll start = min(mina, minb);
    ll stop = max(maxa, maxb);
    for (ll notax = start; notax <= stop; notax++) {
        ll ta = notax * 0.08;
        ll tb = notax * 0.1;
        if (ta == a && tb == b) {
            ans = notax;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int sign[100010];

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> g[100010];
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    queue<int> que;

    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (auto nv : g[v]){
            if (sign[nv] > 0) continue;
            sign[nv] = v + 1;
            que.push(nv);
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < n; i++){
        cout << sign[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 10384
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int D;
vector<int> c(30, 0);
vector<vector<int>> s(400, vector<int>(30, 0));

struct schedule {
	int score = 0;
	vector<int> contest;
	vector<int> last;

	schedule() {
		last.assign(30, 0);
	};

	bool operator<(const schedule& s) const {
		return score > s.score;
	}
};

void input() {
	cin >> D;
	for (int i = 1; i <= 26; ++i) { cin >> c[i]; }
	for (int i = 1; i <= D; ++i) {
		for (int j = 1; j <= 26; ++j) { cin >> s[i][j]; }
	}
}

schedule calc_score(schedule sc, int con) {
	schedule ret = sc;
	int day = sc.contest.size() + 1;
	ret.last[con] = day;
	ret.contest.push_back(con);
	ret.score += s[day][con];
	for (int i = 1; i <= 26; ++i) {
		ret.score -= c[i] * (day - ret.last[i]);
	}

	return ret;
}

int main() {
	constexpr int BEAM = 133;
	input();

	vector<schedule> curr;
	curr.emplace_back(schedule());
	for (int d = 1; d <= D; ++d) {
		vector<schedule> nxt;
		for (auto sc : curr) {
			for (int i = 1; i <= 26; ++i) {
				nxt.push_back(calc_score(sc, i));
			}
		}
		sort(nxt.begin(), nxt.end());
		if (nxt.size() > BEAM) { nxt.resize(BEAM); }
		curr = nxt;
	}
	// cerr << "score = " << curr[0].score << endl;
	for (auto t : curr[0].contest) { cout << t << endl; }

	return 0;
}


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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define MAX 99999999
#define LONGMAX 99999999999999
#define FI first
#define SE second

int main(){
    int N;
    cin >> N;
    vector<int> vec (N);
    for(int i = 0;i < N;i++){
        cin >> vec.at(i);
    }
    int count = 0;
    for(int i = 1;i < N;i++){
        if(vec.at(i) == vec.at(i-1)){
            count++;
            vec.at(i) = 0;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	resolve(parseProblem(os.Stdin))
}

func parseProblem(r io.Reader) (int, *bufio.Scanner) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc), sc
}

func resolve(q int, sc *bufio.Scanner) {
	n := int(1e5)
	primes := eratosthenes(n + 2)
	acc := make([]int, n+2)
	sum := 0
	for i := 1; i <= n+1; i++ {
		acc[i] = sum
		if primes[i] && primes[(i+1)/2] {
			sum++
		}
	}
	res := []int{}
	for i := 0; i < q; i++ {
		l, r := scanInt(sc), scanInt(sc)
		res = append(res, acc[r+1]-acc[l])
	}
	for _, r := range res {
		fmt.Println(r)
	}
	return
}

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func eratosthenes(n int) []bool {
	t := make([]bool, n)
	for i := 2; i < len(t); i++ {
		t[i] = true
	}
	for i := 2; i < len(t); i++ {
		if !t[i] {
			continue
		}
		for j := 2; j*i < len(t); j++ {
			t[j*i] = false
		}
	}
	return t
}

func primes(n int) chan int {
	ch := make(chan int)
	go func() {
		t := eratosthenes(n)
		for i := 2; i < len(t); i++ {
			if !t[i] {
				continue
			}
			ch <- i
		}
		close(ch)
	}()
	return ch
}

func primeFactories(n int) (terms map[int]int) {
	terms = map[int]int{}
	num := n
	for f := 2; f*f <= n; f++ {
		if num%f != 0 {
			continue
		}
		terms[f] = primeExponent(num, f)
	}
	if num > 1 {
		terms[num] = 1
	}
	return
}

func primeExponent(n, p int) (ex int) {
	for n%p == 0 {
		n /= p
		ex++
	}
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6912
<?php
fscanf(STDIN, "%d", $n);
$p = str_replace(array(" ", "\n"), "", fgets(STDIN));
$q = str_replace(array(" ", "\n"), "", fgets(STDIN));

$ranged_n = range(1, $n);
function dfs($ranged_n, $string="") {
	$result = [];
	if (count($ranged_n) == 0) { // 終了条件
		$result[] = $string; // 最終的に欲しい値
	} else {
		foreach ($ranged_n as $key => $val) {
			$_string = $string . $val;
			$_ranged_n = $ranged_n;
			unset($_ranged_n[$key]);
			$pre_result = dfs($_ranged_n, $_string);
			$result = array_merge($result, $pre_result);
		}
	}
	return $result;
}

$list = dfs($ranged_n);
$p_key = array_search($p, $list);
$q_key = array_search($q, $list);
echo abs($p_key - $q_key);

Measured memory_bytes: 10744