akhauriyash/Code-Regression huggingface dataset:
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
void solve(){
  string s,t;cin>>s>>t;
  int n=s.length();
  int cnt=0;
  rep(i,0,n-1){
    if(s[i]!=t[i])cnt++;
  }
  cout<<cnt;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 3812
# https://atcoder.jp/contests/abc077/tasks/arc084_a
import sys
from bisect import bisect_left, bisect_right


def S(): return sys.stdin.readline().rstrip()


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()
B = LI()
C = LI()
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ok_a = bisect_left(A, b)
    ok_c = bisect_right(C,b)
    ans += ok_a * (N-ok_c)
print(ans)


Measured memory_bytes: 92968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<bool> a(m, true);
    rep(i, n) {
        V<bool> now(n, false);
        int k;
        cin >> k;
        rep(j, k) {
            int p;
            cin >> p;
            now[--p] = true;
        }
        rep(j, m) {
            if(!now[j]) a[j] = false;
        }
    }
    int ans = 0;
    rep(i, m) ans += a[i];
    printf("%d\n", ans);
}

Measured memory_bytes: 3728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int s[] = new int[n];
		int sum = 0;

		for (int i = 0; i < n; i++) {
			s[i] = Integer.parseInt(br.readLine());
			sum += s[i];
		}

		Arrays.sort(s);

		if (sum % 10 != 0) {
			System.out.println(sum);
		} else {
			for (int i = 0; i < n; i++) {
				if (s[i] % 10 != 0) {
					System.out.println(sum - s[i]);
					return;
				}
			}
			System.out.println("0");
		}
	}
}


Measured memory_bytes: 32424
#include <stdio.h>
int main()
{
    int a,b,c,k,ans,sum=0;
    scanf("%d",&k);
    for(a=1;a<=k;a++)
    {
        for(b=1;b<=k;b++)
        {
            ans=gcd(a,b);
            for(c=1;c<=k;c++)
            {
                sum=sum+gcd(ans,c);
            }
        }
    }
    printf("%d",sum);
}
int gcd(int a,int b)
    {
        if(a==0)
        {
            return b;
        }else
        {
            return gcd(b % a,a);
        }
    }


Measured memory_bytes: 1720
#include <stdio.h>

constexpr int mod = 1e9 + 7;

int main(void){
    char c;
    long long a = 0, ab = 0, kind = 1, res = 0;;
    while(true){
        c = getchar();
        if(c == '\n' or c == EOF) break;
        if(c == 'A') (a += kind) %= mod;
        else if(c == 'B') (ab += a) %= mod;
        else if(c == 'C') (res += ab) %= mod;
        else if(c == '?'){ 
            ((res *= 3) += ab) %= mod;
            ((ab *= 3) += a) %= mod;
            ((a *= 3) += kind) %= mod;
            (kind *= 3) %= mod;
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

const int MAX_V = 300;

int V;
bool G[MAX_V][MAX_V];
int match[MAX_V];
bool used[MAX_V];

bool dfs(int v) {
	used[v] = true;
	for(int i = 0; i < V; i++) {
		if(!G[v][i]) continue;
		int u = i, w = match[u];
		if(w < 0 || (!used[w] && dfs(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching() {
	int res = 0;
	memset(match, -1, sizeof(match));
	for(int v = 0; v < V; v++) {
		if(match[v] < 0) {
			memset(used, 0, sizeof(used));
			if(dfs(v)) {
				res++;
			}
		}
	}
	return res;
}

int N, M;
int xa[100], ya[100], xb[100], yb[100], v[100];

bool check(double k) {
	memset(G, 0, sizeof G);
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < M; j++) {
			double d = sqrt((xa[i] - xb[j]) * (xa[i] - xb[j]) + (ya[i] - yb[j]) * (ya[i] - yb[j]));
			if(d / v[i] <= k)
				G[i][j + N] = G[j + N][i] = true;
		}
	}

	return bipartite_matching() == M;
}

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

	while(cin >> N >> M, N) {
		V = N + M;
		for(int i = 0; i < N; i++) {
			cin >> xa[i] >> ya[i] >> v[i];
		}
		for(int i = 0; i < M; i++) {
			cin >> xb[i] >> yb[i];
		}

		double ng = 0, ok = 1e9;
		for(int loop = 0; loop < 100; loop++) {
			double mid = (ng + ok) / 2.0;
			if(check(mid)) ok = mid;
			else ng = mid;
		}
		cout << fixed << setprecision(10) << ok << endl;
	}
}

Measured memory_bytes: 3336
package main

import "fmt"

func f(i int) int {
	n := 0
	for i%2 == 0 {
		n++
		i /= 2
	}
	return n
}

func main() {
	var n int
	fmt.Scan(&n)
	ans, x := 0, 0
	for i := 1; i <= n; i++ {
		y := f(i)
		if x <= y {
			ans, x = i, y
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,med1,med2;
    cin >> n;
    vector<int> v(n),u(n);
    for(int i=0;i < n;i++)
    {
        cin >> v.at(i);
    }
    u=v;
    sort(v.begin(),v.end());
    med1=v.at(n/2 -1);
    med2=v.at(n/2);

    for(int i=0;i < n;i++)
    {
        if(u.at(i)<=med1){
            cout << med2 << endl;
        }else if(u.at(i)>=med2){
            cout << med1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3712
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.nextLine()
    println(problem135_d(s))
}

val N = 13
fun problem135_d(s: String): String {

    var dp = arrayOf(1L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

    val mod = 1000000007L

    var mul = 1
    for (index in s.length - 1 downTo 0) {
        val c = s[index]
        val nextDp = arrayOf(0L, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

        if (c == '?') {

            for (k in 0 until 10) {
                addDpTable(nextDp, k, mul, dp, mod)
            }
        } else {
            val k = c - '0'
            addDpTable(nextDp, k, mul, dp, mod)
        }

        mul *= 10
        mul %= N
        dp = nextDp
    }

    return dp[5].toString()
}

private fun addDpTable(
    nextDp: Array<Long>,
    k: Int,
    mul: Int,
    dp: Array<Long>,
    mod: Long
) {
    for (j in 0 until N) {
        val inde = (k * mul + j) % N
        nextDp[inde] += dp[j]
        nextDp[inde] %= mod
    }
}




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

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<int> l(n),r(n);
    l[0] = a[0]; r[n-1] = a[n-1];
    for(int i=0;i<n-1;i++){
        l[i+1] = gcd(a[i+1],l[i]);
        r[n-i-2] = gcd(a[n-i-2],r[n-i-1]);
    }

    int ans = 0;
    for(int i=0;i<n;i++){
        int tmpgcd; 
        if(i==0) tmpgcd = r[1];
        else if(i==n-1) tmpgcd = l[n-2];
        else tmpgcd = gcd(l[i-1], r[i+1]);
        ans = max(ans,tmpgcd);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const MAX = 3e5 + 50;
int a[MAX], b[MAX], c[MAX];
int memo[MAX][4];
int n, k;

int dp(int i, int last)
{
	if(i == n) return 0;
	int &ret = memo[i][last];
	if(ret != -1)
        return ret;
    ret = 0;
	if(last != 1)
		ret = max(ret, dp(i + 1, 1) + a[i]);
	if(last != 2)
		ret = max(ret, dp(i + 1, 2) + b[i]);
	if(last != 3)
		ret = max(ret, dp(i + 1, 3) + c[i]);
	return ret;
}


int main()
{
    memset(memo, -1, sizeof(memo));
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
    	scanf("%d %d %d", &a[i], &b[i], &c[i]);
    }
    printf("%d", dp(0, 0));

	return 0;
}


Measured memory_bytes: 13056
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

double PI = acos(-1);

int N,K;
vector<pair<double,double> > v;
double l[1600],r[1600];
double dp1[1600][1600],dp2[1600][1600];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>K;
	rep(i,N){
		double x,y,R;
		cin>>x>>y>>R;
		double t=atan2(y,x),d=hypot(x,y);
		if(t<-PI/2)t+=PI*2;
		double t2=asin(R/d);
		v.pb(mp(max(0.,t-t2),min(PI,t+t2)));
	}
	sort(v.begin(),v.end());
	N=0;
	rep(i,sz(v)){
		if(N==0 || v[i].sec > r[N-1]){
			l[N]=v[i].fir,r[N]=v[i].sec;
			N++;
		}
	}
	
	rep2(i,1,N+1){
		int pre=i-2;
		while(pre>=0 && r[pre]>l[i-1])pre--;
		pre++;
		if(pre==i-1){
			rep2(j,1,i+1){
				dp1[i][j] = dp2[i-1][j-1] + r[i-1] - l[i-1];
				dp2[i][j] = max(dp2[i-1][j], dp1[i][j]);
			}
		}else{
			rep2(j,1,i+1){
				dp1[i][j] = max(dp2[pre][j-1] + r[i-1] - l[i-1],
				dp1[pre+1][j-1] + r[i-1] - r[pre]);
				dp2[i][j] = max(dp2[i-1][j], dp1[i][j]);
			}
		}
	}
	double ans=0;
	cout<<fixed<<setprecision(16)<<*max_element(dp2[N],dp2[N]+K+1)/PI<<endl;
}

Measured memory_bytes: 39108
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const int INF = 1e9;
vecveci dist(210,veci(210,INF));

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

    vector<int> ri(R);
    REP(i,R) {
        cin >> ri[i];
        ri[i]--;
    }
    
    REP(i,M) {
        int a,b,c; cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = min(dist[a][b],c);
        dist[b][a] = min(dist[b][a],c);
    }

    REP(k,N) REP(i,N) REP(j,N) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);

    int ans = INF;

    sort(ri.begin(),ri.end());

    do{
        int total = 0;
        REP(i,R-1) {
            total += dist[ri[i]][ri[i+1]];
        }
        chmin(ans,total);
    }while(next_permutation(ri.begin(),ri.end()));

    cout << ans << endl;
}


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

int main(){
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> a(H+2, vector<char>(W+2));

  for (int i=0; i<H+2; i++) {
    for (int j=0; j<W+2; j++)
      a.at(i).at(j) = '#';
  }
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++)
      cin >> a.at(i+1).at(j+1);
  }
  for (int i=0; i<H+2; i++) {
    for (int j=0; j<W+2; j++) {
      cout << a.at(i).at(j);
    }
    cout << endl;
  }  
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

#define MAX 100010
int N,D,F[MAX];
ll t[MAX];

bool debug = false;

int main(){
  cin >> N >> D;
  rep(i,N) cin >> t[i] >> F[i];
  if( t[0] < F[0]-1 ) {
    puts("-1");
    return 0;
  }
  ll flr = 1;
  ll tm  = 0;
  ll cnt = 0;
  ll cost = 0;
  rep(i,N) {
    if( debug ) {
      puts("");
      cout << i << "-th" << endl;
      cout << "FLR  = " << flr << endl;
      cout << "time = " << tm << endl;
      cout << "cnt  = " << cnt << endl;
      cout << "cost = " << cost << endl;
    }
    // ???????????¨?????????????¬????????????????
    ll need = (ll)abs(F[i]-flr);
    if(debug){
      cout << "need = " << need << endl;
      cout << tm << " + " << need << " > " << t[i] << endl;
    }
    if( tm + need > t[i] ) {
      puts("-1");
      return 0;
    }

    // ?§????
    tm += need;
    cost += need * cnt;
    flr = F[i];

    // ??????
    ll wait = t[i] - tm;
    if( wait >= 1LL ) {
      cost += wait * cnt;
      tm += wait;
    }

    // ??????
    ++cnt;

    // ??°?????????
    bool ret = false;
    if( cnt && i + 1 < N ) {
      need = flr - 1;
      need += ( F[i+1] - 1 );
      if( tm + need > t[i+1] ) {
	if( cnt >= D ) {
	  puts("-1");
	  return 0;
	} else {


	  if( debug ) {
	    cout << "---END " << i << "--- (RETURN FAILED)" << endl;
	    cout << "need = " << need << endl;
	    cout << tm  << " + " << need << " > " << t[i+1] << endl;
	    cout << "FLR  = " << flr << endl;
	    cout << "time = " << tm << endl;
	    cout << "cnt  = " << cnt << endl;
	    cout << "cost = " << cost << endl;
	  }


	  continue;
	}
      }
      ret = true;
      cost += (ll)(flr-1) * cnt;
      flr = 1;
      tm += (ll)(flr-1);
      cnt = 0;
    }


    if( debug ) {
      cout << "---END " << i << "---" << ( ret ? "(RETURN)" : "" ) << endl;
      cout << "FLR  = " << flr << endl;
      cout << "time = " << tm << endl;
      cout << "cnt  = " << cnt << endl;
      cout << "cost = " << cost << endl;
    }
    
  }
  cost += (ll)(flr-1) * cnt;
  cout << cost << endl;
  return 0;
}

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

int main(void){
	while(1){
		int n,m; cin >> n >> m;
		if(n==0 && m==0) return 0;
		vector<int> p(n);
		for(int i=0;i<n;i++) cin >> p[i];
		p.push_back(0);
		vector<int> pp((n+1)*(n+1));
		int cnt = 0;
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				pp[cnt]=p[i]+p[j];
				cnt++;
			}
		}
		sort(pp.begin(),pp.end());
		int ans = 0;
		for(int i=0;i<(n+1)*(n+1);i++){
			int tmp = pp[i];
			int aim = m-tmp;
			if(aim < 0) continue;
			tmp+=*(upper_bound(pp.begin(),pp.end(),aim)-1);
			if(tmp <= m ) ans = max(ans,tmp);
		}
		printf("%d\n",ans);
	}
	return 0;
}



Measured memory_bytes: 7280
#include <iostream>
#include <vector>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
typedef long long ll;
const int maxx=1e6+10;
ll a[maxx];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,x;
    cin>>n;
    For(i,1,n)cin>>x,a[x]++;
    vector<bool>dv(maxx,true);
    int ans=0;
    For(i,1,maxx)
    {
        if(!a[i])continue;
        if(a[i]==1&&dv[i])ans++;
        for(int j=2; j*i<maxx; j++)dv[i*j]=false;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11584
#include <stdio.h>

int main(void)
{
  int x, y, z;
  scanf("%d %d %d", &x, &y, &z);
  
  int tmp = 0;
  tmp = x;
  x = y;
  y = tmp;
  tmp = z;
  z = x;
  x = tmp;
  printf("%d %d %d", x, y, z);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
typedef pair<int, int> P;
int r,c,k;
int dp[3002][3002][4];
int a[3002][3002];
signed main(){
    cin >> r >> c >> k;
    rep(i,k) {
        int x,y,v;
        cin >> x >> y >> v;
        x--;
        y--;
        a[x][y]=v;
    }
    dp[0][0][0]=0;
    dp[0][0][2]=0;
    dp[0][0][3]=0;
    dp[0][0][1]=a[0][0];
    rep(i,r) {
        rep(j,c) {
            if(i==0) {
                if(j==0) continue;
                FOR(l,1,4) dp[i][j][l] = max(dp[i][j-1][l],(a[i][j]>0)*(dp[i][j-1][l-1]+a[i][j]));
                //cout << i<<j<<" "<<dp[i][j][1] << " "<<dp[i][j][2]<< " "<<dp[i][j][3]<< endl;
                continue;
            }
            int mm = max(dp[i-1][j][1],max(dp[i-1][j][2],max(dp[i-1][j][0],dp[i-1][j][3])));
            dp[i][j][0]=mm;
            if(a[i][j]>0) dp[i][j][1] =mm + (a[i][j]);
            else dp[i][j][1] = 0;
            dp[i][j][2] = 0;
            dp[i][j][3] = 0;
            if(j!=0) {
                dp[i][j][1]=max(dp[i][j][1],max(dp[i][j-1][1],(a[i][j]>0)*(dp[i][j-1][0]+a[i][j])));
                dp[i][j][2]=max(dp[i][j][2],max(dp[i][j-1][2],(a[i][j]>0)*(dp[i][j-1][1]+a[i][j])));
                dp[i][j][3]=max(dp[i][j][3],max(dp[i][j-1][3],(a[i][j]>0)*(dp[i][j-1][2]+a[i][j])));
            }
            //cout << i<<j<<" "<<dp[i][j][0]<<" "<<dp[i][j][1] << " "<<dp[i][j][2]<< " "<<dp[i][j][3]<< endl;
        }
    }
    int ans = 0;
    rep(i,4) ans = max(ans, dp[r-1][c-1][i]); 
    cout << ans << endl;
    return 0;
}

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

res = [0]*N
res[0] = sum(A) - sum(A[1:N-1:2])*2
res[N-1] = A[-1]*2 - res[0]
for i in range(1, N-1):
    res[i] = A[i-1]*2-res[i-1]

print(" ".join(str(n) for n in res))

Measured memory_bytes: 19096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin >> s;
    if(s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    } else{
        cout << "Sunny" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

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

void solve(long long N, std::vector<long long> A){
    V<ll> a1(N), a2(N);
    a1[0] = A[0];
    a2[N - 1] = A[N - 1];
    loop (N - 1, i) {
        a1[i + 1] = gcd(a1[i], A[i + 1]);
        a2[N - 1 - (i + 1)] = gcd(a2[N - 1 - i], A[N - 1 - (i + 1)]);
    }
    ll ans = 1;
    loop (N, i) {
        ll l = i == 0 ? a2[1] : a1[i - 1];
        ll r = i == N - 1 ? a1[N - 2] : a2[i + 1];
        ans = max(ans, gcd(l, r));
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size();i++){
      if(t[i]=='?'){
        cout << 'D';
        }else{
            cout << t[i];
        }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3752
/* ***********************************************
Author        :yang12138
Created Time  :2017年05月06日 星期六 20时47分46秒
File Name     :1.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=1e5+10;
int in[N];

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	int n,m;
	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		in[u]++,in[v]++;
	}

	bool flag=1;
	for(int i=1;i<=n;i++){
		if(in[i]&1) {flag=0;break;}
	}
	if(flag) printf("YES\n");
	else printf("NO\n");
    return 0;
}


Measured memory_bytes: 640
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    long n, m;
    readlnTo(n, m);
    auto red = new bool[](n+1);
    auto num = new int[](n+1);
    red[1] = true;
    num[] = 1;
    foreach(i; iota(m)) {
        long x, y;
        readlnTo(x, y);
        if(red[x]) {
            red[y] = true;
        }
        num[y] += 1;
        num[x] -= 1;
        if(num[x] == 0) {
            red[x] = false;
        }
    }
    writeln(red.filter!(a => a).count);
}



Measured memory_bytes: 1788
s = input()
n = len(s)
#print(s)
rev = ''.join(list(reversed(s)))

#print(rev)
a = int((n-1)/2)
s1 = s[:a]
s_1 = ''.join(list(reversed(s1)))
#print(a, s1, s_1)
b = int((n+3)/2)
s2 = s[b-1:n+1]
s_2 = ''.join(list(reversed(s2)))
#print(b, s2, s_2)

if (s==rev) and (s1 == s_1) and (s2==s_2):
  print('Yes')
else:
  print('No')

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

using namespace std;

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

  int ans = 0;
  while (b <= a) {
    b *= 2;
    ans++;
  }
  while (c <= b) {
    c *= 2;
    ans++;
  }

  cout << (ans <= k ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3536
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] b = new int[n];
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        for(int i = 0; i < n - 1; i++) b[i] = Integer.parseInt(line1[i]);
        int count = 0;
        if(n == 2)  count += b[0] * 2;
        else{
            if(b[0] <= b[1]) count += b[0] * 2;
            else    count += b[0] + b[1];
            for(int i = 1; i < n - 2; i++){
                if(b[i] > b[i + 1]) count += b[i + 1];
                else count += b[i];
            }
            count += b[b.length - 2];
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define ll long long

#define INF 999999999

using namespace std;

// input
int n;
vector<pair<int,bool> > P;

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

    cin >> n;

    int p;

    for(int i = 1;cin >> p;i++){

        P.push_back(make_pair(p,p==i));

    }

    int ans = 0;

    for(int i = 0;i < n; i++){
        if(P[i].second){
            P[i].second = false;
            P[i+1].second = false;
            ans++;
        }
    }

    cout << ans << "\n";
    
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(v <= w) {
        cout << "NO" << endl;
        return 0;
    }
    if(abs(b - a) <= (v - w) * t) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3676
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();

        sc.close();
        if(d==0) {
            if(n==100) n++;
            System.out.println(n);
        }
        else if(d==1) {
            if(n==100)n++; 
            System.out.println(n*100);
        }
        else {
            if(n==100)n++; 
            System.out.println(n*10000);
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    char c;
    cin >> c;
    if (c == 'A') {
        cout << 'T' << endl;
    } else if (c == 'G') {
        cout << 'C' << endl;
    } else if (c == 'T') {
        cout << 'A' << endl;
    } else if (c == 'C') {
        cout << 'G' << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	s := getString()

	ans := len(s)
	for i := 1; i < len(s); i++ {
		substr := s[0 : len(s)-i]
		l := len(substr)
		if l%2 != 0 {
			continue
		}
		if substr[0:l/2] == substr[l/2:l] {
			ans = l
			break
		}
		//		out(substr, substr[0:l/2], substr[l/2:l])
	}
	out(ans)
}


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

main(){
  long long x, y;

  cin >> x >> y;

  if ( x % y == 0) {
    cout << -1 << endl;
  } else {
    printf("%d\n", x*2 % y == 0 ? x * 3 : x * 2);
  }

  return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
#define MAX 10000003
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int c1 = stoi(s1);
    int c2 = stoi(s2);
    int i;
    string d1=s1,d2=s2;
    //cout<<c1<<c2<<e;
    for(i=0;i<c2-1;i++)
        s1+=d1;
    for(i=0;i<c1-1;i++)
        s2+=d2;
    if(s1>s2)
        cout<<s2<<e;
    else
        cout<<s1<<e;
}


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

typedef long long ll;

int main()
{
    ll X;
    cin >> X;

    ll n500 = X / 500;
    ll n5 = (X % 500) / 5;

    cout << n500*1000 + n5*5 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = (int)1e5 + 5;

bool used[MAX_N];	// この数字を使ったかどうか
bool cand[MAX_N];	// この桁が１引く事によって変化するかどうか

int main()
{
	memset(used, false, sizeof(used));
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> a(N, 0);
	rep (i, N) cin >> a[i];

	int res = 0;
	for(int digit = 31; digit >= 0; --digit){
		memset(cand, false, sizeof(cand));
		int cnt = 0;
		rep (i, N){
			if (a[i] & (1<<digit)){
				++cnt;
				if (!used[i] && !((a[i] - 1) & (1<<digit))) cand[i] |= true;
			} // end if
		} // end rep

		if (cnt % 2 == 0){ 
			rep (i, N) used[i] |= cand[i]; // 1 引いて変化するものはもう使えない。よって"使った"にフラグ。
		}else{
			bool one = false;
			rep (i, N){
				if (!used[i] && cand[i]){
					if (!one){
						--a[i];
						++res;
						one |= true;
					} // end if
					used[i] |= true;
				} // end if
			} // end rep
			if (!one){ // 一個もない
				res = -1;
				break;
			} // end if
		} // end if
	} // end for
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    vector<int> a(5);
    rep(i, 5) cin >> a[i];
    int k;
    cin >> k;
    if(a[4] - a[0] <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr ll MOD = 1'000'000'007;
int N, M;
bool broken[100100];
ll dp[100100];

ll rec(int i){
    if(i == N){
        return 1;
    }

    if(broken[i]){
        return 0;
    }

    if(dp[i] != -1){
        return dp[i];
    }

    ll res = 0;

    if(i + 1 <= N){
        res = rec(i + 1);
    }

    if(i + 2 <= N){
        res = (res + rec(i + 2)) % MOD;
    }

    return dp[i] = res;
}

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

    std::cin >> N >> M;

    for(int i=0;i<M;++i){
        int A;
        std::cin >> A;

        broken[A] = true;
    }

    memset(dp, -1, sizeof(dp));

    ll res = rec(0);
    std::cout << res << std::endl;
}


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

using namespace std;

int main(){
  int N, temp, ans;
  cin >> N;
  vector<int> data(N);
  for (int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  for (int i = 1; i < 101; i++){
  temp = 0;
    for (int j = 0; j < N; j++){
    temp += (data.at(j) - i) * (data.at(j) - i);
    }
    if (i == 1) ans = temp;
    else{
      if (ans > temp){
        ans = temp;
      }
    }
  }
  cout << ans;
}

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

int main() {
 string S; cin >> S;
 int X = 0;
 for(char c:S) X+=c-'0';
 printf((X%9==0)?"Yes\n":"No\n");
 return 0;
}

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

int stoi(string str){
  int k = 1,res = 0;
  for(int i=(int)str.size()-1;i>=0;i--){
    res += (str[i]-'0') * k;
    k *= 10;
  }
  return res;
}
int main(){
  int map[100][100];
  int dp[100][100];
  string tmp;
  int n;
  int prv = 0;
  int cnt = 0;

  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++)map[i][j] = 0;
  }

  n = 0;
  while(cin >> tmp){
    int pos = 0;
    vector<int> row;
    while(pos < (int)tmp.size()){
      string digit;
      while(pos < (int)tmp.size() && tmp[pos] != ','){
	digit.push_back(tmp[pos]);
	pos++;
      }
      row.push_back(stoi(digit));
      pos++;
    }

    int s = row.size();
    if(prv > s)cnt++;
    for(int i=0;i<s;i++)map[n-cnt-i][i+cnt] = row[i];

    n++;
    prv = row.size();
  }

  for(int i=0;i<=n/2;i++){
    for(int j=0;j<=n/2;j++){
      if(!i){
	if(!j)dp[i][j] = map[i][j];
	else dp[i][j] = dp[i][j-1] + map[i][j];
      }else{
	if(!j)dp[i][j] = dp[i-1][j] + map[i][j];
	else dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + map[i][j];
      }
    }
  }

  cout << dp[n/2][n/2] << endl;
  
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int ans;
int main() {
	int a,b,c,r;
	cin>>a>>b>>c>>r;
	for(int i=0; i<=a; i++) {
		for(int j=0; j<=b; j++) {
			for(int k=0; k<=c; k++) {
				if(i*500+j*100+k*50==r)
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import collections
k=int(input())
lst = [k+1]*k
q = collections.deque([1])
lst[1] = 1
while q:
    a = q.pop()
    if lst[a*10%k] > lst[a]:
        lst[a*10%k] = lst[a]
        q.append(a*10%k)
    if lst[(a+1)%k]>= lst[a]+1:
        lst[(a+1)%k] = lst[a]+1
        q.appendleft((a+1)%k)
print(lst[0])

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


int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int sum, n, p;
	while (cin >> sum >> n) {
		for (int i = 0; i < n; ++i) {
			cin >> p;
			sum -= p;
		}
		if (sum > 0) cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main( )
{
	int p;
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a){
		cout<<k<<'\n';
		return 0;
	}
	if(k<=a+b){
		cout<<a<<'\n';
		return 0;
	}
	if(k<=a+b+c){
		p=k-(a+b);
		cout<<a-p<<'\n';
		return 0;
	}
	
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 200200
int n,K,l,r,p;
char S[MAX];int a[MAX<<2];
int main()
{
	scanf("%d%d",&n,&K);scanf("%s",S+1);
	l=1,r=n,p=0;
	for(int i=1;i<=n;++i)a[i]=S[i]=='A';
	for(int i=1;i<=n+n;++i)
	{
		if(a[l]^p)a[l]^=1;
		else ++l,p^=1,a[++r]=p^1;
		if(i==K)
		{
			for(int j=l;j<=r;++j)putchar((a[j]^p^1)+'A');
			puts("");return 0;
		}
	}
	if((n&1)&&(K&1))a[l]^=1;
	for(int i=l;i<=r;++i)putchar((a[i]^p^1)+'A');
	return 0;
	
}


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

vector<int> P,jun;

int main(void){
  int N;
  cin >> N;
  P = vector<int>(N);
  jun = vector<int>(N);
  string S[N];

  for(int i=0;i<N;i++){
    cin >> S[i] >> P[i];
    jun[i] = i+1;
  }

  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(S[i] > S[j]){
        string tmps;
        int nump,numjun;
        tmps = S[i];
        S[i] = S[j];
        S[j] = tmps;
        nump = P[i];
        P[i] = P[j];
        P[j] = nump;
        numjun = jun[i];
        jun[i] = jun[j];
        jun[j] = numjun;
      }else if(S[i] == S[j]){
        if(P[i] < P[j]){
          string tmps;
          int nump,numjun;
          tmps = S[i];
          S[i] = S[j];
          S[j] = tmps;
          nump = P[i];
          P[i] = P[j];
          P[j] = nump;
          numjun = jun[i];
          jun[i] = jun[j];
          jun[j] = numjun;
        }
      }
    }
  }
  for(int i=0;i<N;i++){
    cout << jun[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int a= sc.nextInt();
   int b= sc.nextInt();
   int c= sc.nextInt();
   int d= sc.nextInt();
   boolean flag = true;

   while(flag) {
	   c -= b;
	   if(c<=0) {
		   System.out.println("Yes");
		   flag = false;
		   break;
	   }
	   a -= d;
	   if(a<=0) {
		   System.out.println("No");
		   flag = false;
		   break;
	   }
   }

 }
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K=38,N=K*(K-1)+1;
    cout << N << ' ' << K << '\n';
    for (int i=0;i<K;++i){
        cout << 1;
        for (int j=0;j<K-1;++j){
            cout << ' ' << 2+(K-1)*i+j;
        }
        cout << '\n';
    }
    for (int i=0;i<N-K;++i){
        cout << 2+i/(K-1);
        for (int j=0,d=i%(K-1);j<K-1;++j,(d+=i/(K-1))%=(K-1)){
            cout << ' ' << K+1+j*(K-1)+d;
        }
        cout << '\n';
    }
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <string>
#define LL long long
#define num1 2000
#define num2 2000
#define rep(i,n) for(i=0;i<=(n-1);i++)
using namespace std;

//vector<string> S;
char S[100];
int len,i;
int flg;

// func: get char type str length.
int length(char x[]){
  int i;
  while(x[i]){
  	i++;
  }
 	return i;
}

int main(){
  
  scanf("%s",&S);	
  
  len = length(S);
  
  flg=0;
  
  rep(i,len){
    
    if((i+1)%2==0){
    	
      if(!(S[i]=='L'||S[i]=='U'||S[i]=='D')){
      	
      	flg=1;
        //cout << S[i] << endl;

        
      }
    
    }else{
    
      if(!(S[i]=='R'||S[i]=='U'||S[i]=='D')){
       
        flg=1;
        //cout << S[i] << endl;

      }
    
    
    }
  
  
  }
  
 
 flg==1?puts("No"):puts("Yes");
  
  return 0;
}








Measured memory_bytes: 256
n,k = map(int,input().split())
s = list(map(int,input().split()))
# print(s)
now_city = 1
s_l_city = 1
t = [0] #何回そこを通ったか
f = [0] #何回目にそこを通ったか
a=0
b = 0#サイクルありなし
f_l=0#ループの最初

#【ループ回数】200000
for i in range(n):
    t.append(0)
    f.append(-1)
# print(s)
sycle = 0
#【ループ回数】200000
for i in range(1,n+10):
    now_city = s[now_city-1]

    if t[now_city-1]==1:
        #  print(i,f[j])
         sycle=i-f[now_city-1]
         f_l=f[now_city-1]
        #  f_l=i
        #  a = 1
         b = i
        #  s_l_city=now_city
        #  print("ループの最初の数字",now_city,"最初は"+str(f_l)+"回目","周期は",sycle)
         break
    t[now_city-1]+=1
    f[now_city-1]=i
# print(t)
# print(f_l)
# print(f_l,sycle,s_l_city)

if k>b:
    # now_city=s_l_city
    for _ in range((k-f_l)%sycle):

        now_city = s[now_city-1]
    # print((k-f_l)%sycle)
    print(now_city)
else:
    # print("ループなし")
    now_city=1
    for _ in range(k):
        now_city=s[now_city-1]
    print(now_city)


Measured memory_bytes: 32344
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int[] list = new int[N];
    double ans = 0;
    for(int i = 0; i < N; i++){
      list[i] = sc.nextInt();
      ans += list[i];
    }
    
    double ave = ans / N;
   
    double distance = (double)Math.abs(list[0]-ave);
 
    int answer = 0;
    for(int i = 1; i < list.length; i++){
      double nextDistance = (double)Math.abs(list[i]-ave);
      if(nextDistance < distance){
        answer = i;
        distance = nextDistance;
      }
    }
    
    
    for(int i = 0; i < list.length; i++){
      if((double)Math.abs(list[i]-ave) == distance){
        System.out.println(i);
        break;
      }
    }
  }
}

Measured memory_bytes: 35760
#include <stdio.h>
#include <algorithm>
#include <vector>


using LL = long long ;
const int kN = 100000 + 5;
int n, m, a[kN];
LL b[kN];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i)
        scanf("%d", a + i);

    LL result = 0;
    for (int i = 1; i < n; ++ i) {
        result += (a[i + 1] - a[i] + m) % m;
        if (a[i] < a[i + 1]) {
            b[a[i] + 2] += 1;
            b[a[i + 1] + 1] += -(a[i + 1] - a[i]);
            b[a[i + 1] + 2] += a[i + 1] - a[i] - 1;
        } else {
            if (a[i] != m) {
                b[a[i] + 2] += 1;
            }
            if (a[i + 1] == 1) {
                b[1] += m - a[i];
                b[2] += -(2 * (m - a[i]));
                b[3] += m - a[i];
            } else {
                b[1] += m - a[i];
                b[2] += 1 - (m - a[i]);
                b[a[i + 1] + 1] += -(m - a[i] + a[i + 1]);
                b[a[i + 1] + 2] += m - a[i] + a[i + 1] - 1;
            }
        }
    }
    for (int i = 2; i <= m; ++ i)
        b[i] += b[i - 1];
    for (int i = 2; i <= m; ++ i)
        b[i] += b[i - 1];
    printf("%lld\n", result - *std::max_element(b + 1, b + m + 1));
}


Measured memory_bytes: 1280
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;
int main(){
    ll Q;
    cin >> Q;
    priority_queue<ll> p;
    priority_queue<ll,vector<ll>,greater<ll>> q;
    ll sum_p=0,sum_q=0;
    ll c=0;
    ll i=0;
    while(Q--){
        ll k;
        cin >> k;
        if(k==1){
            ll a,b;
            cin >> a >> b;
            c+=b;
            if(p.empty()){
                p.push(a);
                sum_p+=a;
                continue;
            }
            if(q.empty()){
                ll x=p.top();
                if(x<=a){
                    q.push(a);
                    sum_q+=a;
                }
                else{
                    p.pop();
                    sum_p-=x;
                    p.push(a);
                    sum_p+=a;
                    q.push(x);
                    sum_q+=x;
                }
                continue;
            }
            ll x=p.top();
            if(p.size()==q.size()){
                if(a<=x){
                    p.push(a);
                    sum_p+=a;
                }
                else{
                    q.push(a);
                    sum_q+=a;
                    ll y=q.top();
                    q.pop();
                    sum_q-=y;
                    p.push(y);
                    sum_p+=y;
                }
            }
            else{
                
                p.push(a);
                sum_p+=a;
                ll y=p.top();
                p.pop();
                sum_p-=y;
                q.push(y);
                sum_q+=y;
            }
            
        }
        if(k==2){
            ll x=p.top();
            ll y=q.top();
            ll ans=0;
            ans+=x*p.size()-sum_p;
            ans+=sum_q-x*q.size();
            ans+=c;
            cout << x << " " << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5088
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int black[n + 1] = {},white[n + 1] = {};
    for(int i = 0;i < n;i++)
    {
        if(s[i] == '#')
        {
            black[i + 1] = black[i] + 1;
            white[i + 1] = white[i];
        }
        else
        {
            black[i + 1] = black[i];
            white[i + 1] = white[i] + 1;
        }
    }
    int ans = INT_MAX;
    for(int i = 0;i < n + 1;i++)
    {
        int temp = (black[i] - black[0]) + (white[n] - white[i]);
        if(temp < ans)
        {
            ans = temp;
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    string S;
    cin>>S;
    int c0=0,c1=0;
    rep(i,sz(S)){
        if(S.at(i)=='0')c0++;
        else c1++;
    }
    cout<<min(c0,c1)*2<<endl;
}

Measured memory_bytes: 3752
import math
def main():

    X = int(input())
    if X == 1: return 2

    def isprime(n):
        for i in range(2, int(math.sqrt(n))+1):
            if n % i == 0:
                return False
        return True

    n = X
    while True:
        if isprime(n):
            return n
        n += 1
    return -1

if __name__ == '__main__':
    print(main())

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  
  string S;
  cin >> S;
  
  int mods[S.length()+1];
  int ketamod[S.length()];
  int modvs[2020];
  rep(i,2020) modvs[i] = 0;
  
  ll ans=0;
  mods[S.length()] = 0;
  for(ll i=S.length()-1; i>-1; i--){
    if(i==S.length()-1){
      ketamod[i] = 1;
      mods[i] = (int)(S[i]-'0');
    }else{
      ketamod[i] = ketamod[i+1]*10;
      ketamod[i] = ketamod[i]%2019;
      mods[i] = mods[i+1]+ketamod[i] * (int)(S[i]-'0');
      mods[i] = mods[i]%2019;
      if(mods[i]==0) ans++;
    }
    
    modvs[mods[i]]++;
  }
  
  rep(i,2020){
    ans += modvs[i]*(modvs[i]-1)/2;
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 5216
#include <stdio.h>

#define MAX_N 100

int main(){
  int n,max,min,i,arr[MAX_N],sum;
  while(1){
    max = sum = 0; min = 1000;
    scanf("%d",&n);
    if(n == 0){ break; }
    for(i = 0 ; i < n ; i++){
      scanf("%d",&arr[i]);
      if(max < arr[i]){ max = arr[i]; }
      if(min > arr[i]){ min = arr[i]; }
      sum += arr[i];
    }
    printf("%d\n",(sum-max-min)/(n-2));
  }
  return 0;
}

Measured memory_bytes: 600