akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin>>S;
    if(S.size()==3){
        reverse(S.begin(),S.end());
    }
    cout << S << endl;



}


Measured memory_bytes: 3596
import bisect


A, B, Q = map(int, input().split())

virtual = 10**18

list_s = [-virtual] + [int(input()) for a in range(A)] + [virtual]
list_t = [-virtual] + [int(input()) for b in range(B)] + [virtual]

list_x = [int(input()) for q in range(Q)]

for q in range(Q):
	x = list_x[q]
	n, m = bisect.bisect_left(list_s, x), bisect.bisect_left(list_t, x)
	list_dist = []
	for S in [list_s[n-1], list_s[n]]:
		for T in [list_t[m-1], list_t[m]]:
			d_s = abs(S - x) + abs(S - T)
			d_t = abs(T - x) + abs(S - T)
			result = min(virtual, d_s, d_t)

			list_dist.append(result)
	
	min_result = min(list_dist)
	print(min_result)

Measured memory_bytes: 17936
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
#else
using LONG = long long int;
#endif

int main(void) {
  string str; int K;
  cin >> str >> K;
  REP(i, str.size()) {
    if (str[i] == 'a') continue;
    if (K < 26 - (str[i] - 'a')) continue;
    K -= (26 - (str[i] - 'a'));
    str[i] = 'a';
    if (K < 0) break;
  }
  if (K > 0) {
    str[str.size() - 1] = (str[str.size() - 1] - 'a' + K) % 26 + 'a';
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;
int A, B, C;

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

  cin >> A >> B>> C;
  string ans = C <= A+B? "Yes" :"No";
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());

		int[] d = new int[n];

		for (int i = 0; i < n; i++) {
			d[i] = Integer.parseInt(sc.next());
		}
		int ans = 0;

		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				ans += d[i] * d[j];
			}
		}

		System.out.println(ans);
		sc.close();
	}
}

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


void solve(long long X){
    // それぞれは枚数
    long long x1000 = (long long) (X / 500);
    long long x5 = (X - (long long)(x1000 * 500)) / 5;
    
    cout << x1000*1000 + x5*5 << endl;
    
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] strs = sc.next().split("");

		int result = Arrays.stream(strs)
			.mapToInt(Integer::parseInt)
			.sum();
      
		System.out.println(result);
	}
}


Measured memory_bytes: 26580
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
using ll = long long;
using P = pair<ll, int>;

const int mod = 1000000007;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

struct Edge{
	int to;
	ll cost;
	Edge(int t, ll c) : to(t), cost(c){}
};

using p_vec = pair<vector<ll>, vector<mint>>;

int n;
vector<vector<Edge>> g; 

p_vec dijkstra(int start){
	vector<ll> dist(n, LINF);
	vector<mint> cnt(n, 0); 
	priority_queue<P, vector<P>, greater<P>> que;
	cnt[start] = 1;
	dist[start] = 0;
	que.push({dist[start], start});

	while(!que.empty()){
		auto v = que.top();
		que.pop();
		int from = v.second;
		ll d = v.first;
		if(d > dist[from])continue;

		for(auto nv : g[from]){
			int to = nv.to;
			ll cost = nv.cost;
			if(dist[from] + cost < dist[to]){
				cnt[to] = cnt[from];
				dist[to] = dist[from] + cost;
				que.push({dist[to], to});
			}
			else if(dist[from] + cost == dist[to]){
				cnt[to] += cnt[from];
			}
		}
	}

	return {dist, cnt};
}

int main(){
  int m, s, t;
  cin >> n >> m >> s >> t;
  --s;
  --t;
  g.resize(n);
  for(int i = 0; i < m; ++i){
  	int u, v;
  	ll d;
  	cin >> u >> v >> d;
  	--u;
  	--v;
  	g[u].push_back(Edge(v, d));
  	g[v].push_back(Edge(u, d));
  }

  auto dij_s = dijkstra(s);
  auto dist_s = dij_s.first;
  auto cnt_s = dij_s.second;
  auto dij_t = dijkstra(t);
  auto dist_t = dij_t.first;
  auto cnt_t = dij_t.second;

  ll total_dist = dist_s[t];
  mint ans = cnt_s[t] * cnt_t[s];
  for(int i = 0; i < n; ++i){
  	if(dist_s[i] * 2 == dist_s[t]){
  		ans -= (cnt_s[i] * cnt_t[i]).pow(2);
  	}
  	for(auto nv : g[i]){
  		int from = i;
  		int to = nv.to;
  		ll cost = nv.cost;
  		if(dist_s[from] * 2 < dist_s[t] && dist_s[t] < dist_s[to] * 2){
  			if(dist_s[from] + cost + dist_t[to] == total_dist){
  				ans -= (cnt_s[from] * cnt_t[to]).pow(2);
  			}
  		}
  	}
  }

  
  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 20308
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main()
{
	int h1,h2,m1,m2,k,ans=0;
	cin>>h1>>m1>>h2>>m2>>k;
	h1*=60;
	h2*=60;
	ans=h2-h1+(m2-m1)-k;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3164
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	while(true){
	    int a=sc.nextInt();
	    String op=sc.next();
	    int b=sc.nextInt();
	    if(op.equals("?"))break;
	    int ans=a+b;
	    if(op.equals("-"))ans=a-b;
	    if(op.equals("*"))ans=a*b;
	    if(op.equals("/"))ans=a/b;
	    System.out.println(ans);
	}
	
    }
    public static void main(String[]ag){
	new Main().main();
    }
}

Measured memory_bytes: 26352
m, d = gets.split.map(&:to_i)

all_days = Array.new(d) { |i| i + 1 }

multiplication_days =
  all_days.delete_if { |x| x.to_s[0].to_i < 2 || x.to_s[1].to_i < 2 }
  .delete_if { |x| x.to_s[0].to_i * x.to_s[1].to_i > m }

puts multiplication_days.size


Measured memory_bytes: 1788
#include <iostream>

using namespace std;


int ketawa(int n)
{
	int sum = 0;

	while (n > 0)
	{
		sum += n % 10;
		n /= 10;

	}

	return sum;
}


int main()
{
	int N, A, B;
	cin >> N >> A >> B;

	int total = 0;

	for (int i = 1; i <= N; ++i)
	{
		int ketasum = ketawa(i);

		if (ketasum >= A && ketasum <= B)
		{
			total += i;
		}

	}
	cout << total;
}



Measured memory_bytes: 3632
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		String A=in.next();
		String B=in.next();
		int dp[][]=new int[A.length()+1][B.length()+1];
		for(int i=0;i<=A.length();i++)
		{
			for(int j=0;j<=B.length();j++)
			{
				if(i==0 || j==0)
					dp[i][j]=0;
				else if(A.charAt(i-1)==B.charAt(j-1))
					dp[i][j]=1+dp[i-1][j-1];
				else
					dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
			}
		}
		StringBuffer S=new StringBuffer();
		int i=A.length(),j=B.length();
		while(i>0 && j>0)
		{
			if(A.charAt(i-1)==B.charAt(j-1))
			{
				S.append(A.charAt(i-1));
				i--;
				j--;
			}
			else if(dp[i-1][j]>dp[i][j-1])
				i--;
			else
				j--;
		}
		String s=new String(S.reverse());
		System.out.println(s);
	}
}


Measured memory_bytes: 82516
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<bool> avail = {false, false, false, false, false, false, false, false, false, false};
    string N;
    int D;
    string res = "";
    cin >> N >> D;
    int MIN = 0;
    for (int i = 0; i < D; i++)
    {
        int a;
        cin >> a;
        avail[a] = true;
    }
    for (int i = 0; i < avail.size(); i++)
    {
        if (avail[MIN] == true)
        {
            MIN = MIN + 1;
        }
        else
        {
            break;
        }
    }

    bool new_size = false;
    bool test = false;
    for (int i = 0; i < N.size(); i++)
    {
        if (test == true)
        {
            res += to_string(MIN);
        }
        else if (new_size == false)
        {
            if (int(N[i] - 48) == 9 && avail[int(N[i] - 48)])
            {
                new_size = true;
                if (MIN == 0)
                {
                    for (int a = MIN + 1; a < avail.size(); a++)
                    {
                        if (!avail[a])
                        {
                            res += to_string(a);
                            test = true;
                            break;
                        }
                    }
                }
                else
                {
                    res += to_string(MIN);
                }
            }
            else if (!avail[int(N[i] - 48)])
            {
                res += to_string(int(N[i] - 48));
            }
            else
            {
                bool t = false;
                for (int a = int(N[i] - 48) + 1; a < avail.size(); a++)
                {

                    if (!avail[a])
                    {
                        t = true;
                        res += to_string(a);
                        test = true;
                        break;
                    }
                }
                if (!t)
                {
                    new_size = true;
                    res += to_string(MIN);
                    
                }
            }
        }
        else
        {
            res += to_string(MIN);
        }
    }

    if (new_size == true)
    {
        res += to_string(MIN);
    }
    cout << stoi(res) << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	if n%2 == 0 {
		fmt.Println(0.5)
	} else {
		fmt.Printf("%.7f\n", ((float64(n)+1.0)/2.0)/float64(n))
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

S=one_str()

dicts ={"SUN":7,"MON":6,"TUE":5,"WED":4,"THU":3,"FRI":2,"SAT":1}

print(dicts[S])

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, s1, s2, ans = 1e9;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
        s1 = s2 = 0;
        for (int j = 0; j < i; j++) {
            s1 += a[j];
        }
        for (int k = i; k < n; k++) {
            s2 += a[k];
        }
        if (abs(s1 - s2) < ans) ans = abs(s1 - s2);
    }
    cout << ans << '\n';
    return 0;
}

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

int main(){
  string s;
  int k;
  cin>>s;
  k=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C'&&k==0)k++;
    else if(k==1&&s[i]=='F'){
      k=2;
      break;
    }
  }
  if(k==2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int mini = INF;

    for(int i = 0; i <= 100000; i++){
        int price = 0;
        int ap = (X - i) * A;
        if(ap < 0) ap = 0;
        int bp = (Y - i) * B;
        if(bp < 0) bp = 0;
        int abp = (i * 2) * C;
        price = ap + bp + abp;
        mini = min(mini, price);
    }

    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,sum=0,s=0;
	cin>>n;
	int t,w;
	cin>>t>>w;
	for(int i=1;i<=n;i++)
	{
		int m=i;
		sum=0;
		while(m!=0)
		{
			int temp=m%10;
			m=m/10;
			sum+=temp;
		}
		if(sum>=t&&sum<=w)
		s+=i;
	}
	cout<<s;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
  int H,W;
  scanf("%d", &H);
  scanf("%d", &W);
  vector<vector <char > > C(H, vector<char>(W));
  for(int i=0; i < H; i++)
    for(int j=0; j < W; j++)
      scanf(" %c", &C[i][j]);
  for(int i=0; i < 2*H; i++){
    for(int j=0; j < W; j++){
      printf("%c", C[i/2][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<vector<bool>> L(N, vector<bool>(N, false));
    for (int i = 0; i < N; i++){
      int M;
      cin >> M;
      for (int j = 0; j < M; j++){
        int p;
        cin >> p;
        p--;
        L[i][p] = true;
      }
    }
    vector<bool> L2(N, false);
    int K;
    cin >> K;
    for (int i = 0; i < K; i++){
      int l;
      cin >> l;
      l--;
      L2[l] = true;
    }
    vector<int> ans;
    for (int i = 0; i < N; i++){
      bool ok = true;
      for (int j = 0; j < N; j++){
        if (!L[i][j] && L2[j]){
          ok = false;
        }
      }
      if (ok){
        ans.push_back(i);
      }
    }
    if (ans.size() == 1){
      cout << ans[0] + 1 << endl;
    } else {
      cout << -1 << endl;
    }
  }
}


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

int main(){
  int n;
  cin >> n;
  int tmp = n;
  int sum = 0;
  while(tmp > 0){
    sum += tmp % 10;
    tmp /=10;
  }
  if(n % sum == 0) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[]
count=0
for i in range(m):
  l1=list(map(int,input().split()))
  del l1[0]
  l.append(l1)
lm=list(map(int,input().split()))
for i in range(2**n):
  c2=0
  l2=[]
  for j in range(n):
    if i>=2:
      l2.append(i%2)
      i=i//2
    else:
      l2.append(i)
      i=i//2
  for j in range(m):
    c=0
    for k in range(len(l[j])):
      if l2[l[j][k]-1]==1:
        c+=1
    if c%2==lm[j]:
      c2+=1
  if c2==m:
    count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int h,w;
int ch, cw;
int dh, dw;
char s[1000][1000];
int g[1000][1000];
struct qs {int y; int x; int d;};
set<pair<pair<int, int>,int>> q;

void q_push(int y, int x, int d) {
  if (y<0 || y>=h || x<0 || x>=w ||
      s[y][x] == '#' ||
      (g[y][x] >= 0 && g[y][x] < d)) return;
//printf("q_push(%d, %d, %d)\n", y, x, d);
  q.insert(make_pair(make_pair(y, x), d));
}

int main()
{

  cin >> h >> w;
  cin >> ch >> cw;
  cin >> dh >> dw;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin >> s[i][j];
      g[i][j] = -1;
    }
  }

  q_push(ch-1, cw-1, 0);
  while (q.size()>0) {
    int x, y, d;
    auto it=q.begin();
    d = it->second;
    y = it->first.first;
    x = it->first.second;
    q.erase(*it);
    if (y<0 || y>=h || x<0 || x>=w ||
        s[y][x] == '#' ||
        (g[y][x] >= 0 && g[y][x] <= d)) continue;
//printf("g[%d][%d] = %d\n", y, x, d);
    g[y][x] = d;

    q_push(y-1, x, d);
    q_push(y+1, x, d);
    q_push(y, x-1, d);
    q_push(y, x+1, d);

    q_push(y-1, x-1, d+1);
    q_push(y-1, x+1, d+1);
    q_push(y+1, x-1, d+1);
    q_push(y+1, x+1, d+1);

    for (int i=-2; i<=2; i++) {
      q_push(y+i, x-2, d+1);
      q_push(y+i, x+2, d+1);
    }
    for (int i=-1; i<=1; i++) {
      q_push(y-2, x+i, d+1);
      q_push(y+2, x+i, d+1);
    }
  }

  cout << g[dh-1][dw-1] << endl;
  return 0;
}


Measured memory_bytes: 9288
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    count = 0
    for j in range(26):
        if chr(ord("a") + j) in X and chr(ord("a") + j) in Y:
            count += 1
    if count > ans:
        ans = count
print(ans)


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0; i < len; i++)
    {
        if(s[i] == ',')
        {
            s[i] = ' ';
        }
    }
    cout << s << " ";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

typedef long long LL;
const int MN = 100005;

int N, V, P, p[MN], Ans;
LL M, A[MN], S[MN];

int main() {
	scanf("%d%lld%d%d", &N, &M, &V, &P);
	for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]), p[i] = i;
	std::sort(p + 1, p + N + 1, [](int i, int j) { return A[i] > A[j]; });
	int J = 0, K = 0;
	for (int I = 1; I <= N; ++I) {
		int i = p[I];
		S[I] = S[I - 1] + A[i];
		while (J < N && A[p[J + 1]] > A[i] + M) ++J;
		while (K < N && A[p[K + 1]] > A[i]) ++K;
		if (K < P) { ++Ans; continue; }
		if (J >= P) continue;
		int L = (P - 1) + (N - K) <= V ? V - ((P - 1) + (N - K)) : 0;
		if (L * M <= (K - (P - 1)) * (A[i] + M) - (S[K] - S[P - 1])) ++Ans;
	}
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x;}
vector<P> factorize(ll x) {
  vector<P> res;
  for(ll i = 2; i * i <= x; ++i) {
    if(x % i) continue;
    res.emplace_back(i, 0);
    while (!(x % i)) {
      res.back().second++;
      x /= i;
    }
  }
  if(x != 1) res.emplace_back(x, 1);
  return res;
}

int main(){
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  auto primes = factorize(g);
  cout << primes.size() + 1 << endl;

}

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

typedef long long ll;
const int maxn = 50005;
const int INF = 1e9;
const ll INF_LL = 1e18;
int e_num = 1, S, T, ans = 0;
ll mincost = 0;
int hed[maxn];
ll ct[maxn];

struct Edge {
  int from, to, nxt, c; ll cost;
} edge[maxn * 4];
void addedge(int from, int to, int c, ll cost) {
  edge[++e_num] = (Edge){from, to, hed[from], c, cost};
  hed[from] = e_num;
}
void adde(int from, int to, int c, ll cost) {
  addedge(from, to, c, cost);
  addedge(to, from, 0, -cost);
}
queue <int> q;
#define prev prv
int inq[maxn], prev[maxn], pree[maxn];
bool SPFA() {
  for (int i = 0; i <= T; i++) ct[i] = INF_LL;
  inq[S] = 1;
  ct[S] = 0;
  q.push(S);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = hed[cur]; i; i = edge[i].nxt) {
      int to = edge[i].to;
      if (ct[to] > ct[cur] + edge[i].cost && edge[i].c) {
        if (!inq[to]) {
          inq[to] = 1;
          q.push(to);
        }
        ct[to] = ct[cur] + edge[i].cost;
        prev[to] = cur;
        pree[to] = i;
      }
    }
    inq[cur] = 0;
  }
  if (ct[T] == INF_LL) return 0;
  int flow = INF;
  for (int cur = T; prev[cur]; cur = prev[cur]) {
    int ed = pree[cur];
    flow = min(flow, edge[ed].c);
  }
  for (int cur = T; prev[cur]; cur = prev[cur]) {
    int ed = pree[cur];
    edge[ed].c -= flow;
    edge[ed ^ 1].c += flow;
  }
  ans += flow;
  mincost += flow * ct[T];
  return 1;
}

int n;
int main() {
  scanf("%d", &n);
  S = n * 2 + 5, T = n * 2 + 6;
  for (int i = 1; i <= n; i++) {
    ll x, y; int c;
    scanf("%lld%lld%d", &x, &y, &c);
    adde(S, i, c, 0);
    adde(i, n * 2 + 1, c, x + y);
    adde(i, n * 2 + 2, c, - x - y);
    adde(i, n * 2 + 3, c, x - y);
    adde(i, n * 2 + 4, c, - x + y);
  }
  for (int i = 1; i <= n; i++) {
    ll x, y; int c;
    scanf("%lld%lld%d", &x, &y, &c);
    adde(i + n, T, c, 0);
    adde(n * 2 + 1, i + n, c, - x - y);
    adde(n * 2 + 2, i + n, c, x + y);
    adde(n * 2 + 3, i + n, c, - x + y);
    adde(n * 2 + 4, i + n, c, x - y);
  }
  while (SPFA());
  printf("%lld\n", -mincost);
  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#define _USE_MATH_DEFINES
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
#define Rep(i,n) for(int i = 0;i < (n);i++)	
typedef long long ll;

int gcd(int a, int b) { if (b == 0)  return a;  else  return gcd(b, a % b); }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int& a, int& b) { int temp = a; a = b; b = temp; return; }
int ncr(int n, int r) { int a = 1; Rep(i, r) a = (a * (n - i)) / (i + 1); return a; }
int npr(int n, int r) { int a = 1; Rep(i, r) a *= n - i; return a; }
int mod(int a, int b) { return a % b; }

int main() {
	double a, b;
	double h, m;
	double ans;
	std::cin >> a >> b >> h >> m;
	double hv = M_PI / 360;
	double mv = M_PI / 30;
	double time = h * 60 + m;
	double h_rad = hv * time;
	double m_rad = mv * time;
	while (m_rad>=2*M_PI) {
		m_rad =m_rad - 2 * M_PI;
	}
	double yaw = m_rad - h_rad;
	if (m_rad - h_rad > M_PI) {
		yaw = 2 * M_PI - yaw;
	}
	ans = sqrt(pow(a, 2) + pow(b, 2) - 2.0 * a * b * cos(yaw));
	printf("%30.20f", ans);


	return 0;
}

Measured memory_bytes: 4140
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for i in range(N)])

    tmp = 0
    for i in range(N):
        a, b = ab[i]
        tmp += b
        if tmp >= K:
            print(a)
            return


if __name__ == "__main__":
    main()

Measured memory_bytes: 28648
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int ar[200000],dp[200000],n;
int solve(int i)
{
    dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
    if(i==n||n==1||n==2)
    return dp[n];
    solve(i+1);
}
int main()
{
    SYNC
    in(n);
    l(i,1,n+1)
    in(ar[i]);
    dp[1]=0;
    dp[2]=abs(ar[1]-ar[2]);
    o(solve(3));
}


Measured memory_bytes: 1024
x = int(input())
s = [1]
for i in range(2, 32):
    if not i in s:
        n = i * i
        while True:
            if n <= 1000 and not n in s:
                s.append(n)
            if n > 1000:
                break
            n *= i
s.sort()
for i in s:
    if i <= x:
        ans = i
    else:
        break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
#define pb push_back
#define fi first
#define se second
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1LL<<60;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
int main(){
    int n;
    cin>>n;
    vi vec(n);
    map<int,int> ma;
    REP(i,n){
        cin>>vec[i];
        ma[vec[i]]++;
    }
    int ans=0;
    REPR(i,30){
        for(auto itr:ma){
            if(ma.count((1<<i)-itr.fi)){
                if((1<<i)-itr.fi==itr.fi){
                    ans+=ma[itr.fi]/2;
                    ma[itr.fi]%=2;
                }else{
                    int k=min(itr.se,ma[(1<<i)-itr.fi]);
                    ma[itr.fi]-=k;
                    ma[(1<<i)-itr.fi]-=k;
                    ans+=k;
                }
                    
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

std::vector<std::vector<long long> > comb(int n, int r) {
  std::vector<std::vector<long long> > v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main(){

  ll n,p;
  cin >> n >> p;
  ll a[n];
  multiset<ll> s;
  rep(i,n){
    cin >> a[i];
    a[i]%=2;
    s.insert(a[i]);
  }
  ll cz=s.count(0);
  ll co=s.count(1);
  ll fac=pow(2,cz);
  ll ans=0;
  rep(i,co+1){
    if(i%2==p){
      if(i==0){
	ans+=fac;
	continue;
      }
      ans += comb(co,i)[co][i]*fac;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define N 200005
int a[N],d[N];

int check(int n){
    int i;
    for(i=1;i<=n;i++){
        if(a[i]!=n)
            return 0;
    }
    return 1;
}

int main(){
    int n,k,i,l,r;
    cin>>n>>k;
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    
    while(k--){
        memset(d,0,sizeof(d));
        for(i=1;i<=n;i++){
            l=i-a[i];
            r=i+a[i];
            if(l<1)
                l=1;
            if(r>n)
                r=n;
            d[r+1]-=1;
            d[l]+=1;
        }
        a[1]=d[1];
        for(i=2;i<=n;i++){
            d[i]+=d[i-1];
            a[i]=d[i];
        }
        if(check(n)){
            for(i=1;i<=n;i++){
                cout<<n<<" ";
            }
            return 0;
        }
        
        
    }
    for(i=1;i<=n;i++){
        cout<<a[i]<<" ";
    }
    return 0;
}


Measured memory_bytes: 5200
N = int(input())
mod = 10 ** 9 + 7
memo = [{} for i in range(N + 1)]
#最新の４文字について、隣接２文字の入れ替えをしてもAGCは現れないかどうか
def check(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i-1], t[i] = t[i], t[i-1]
    if ''.join(t).count('AGC') >= 1:
      return False
  return True
#深さ優先　メモ化再帰
def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  ret = 0
  #ACGTのうち１文字を末尾に加える
  for c in 'ACGT':
    #checkを通ったのなら、retに次の文字列の個数を加算
    if check(last3 + c):
      ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod
  memo[cur][last3] = ret
  return ret
print(dfs(0, 'TTT'))

Measured memory_bytes: 48220
#include <iostream>
#include <string>
#include<vector>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>
#include<climits>
#include <utility>
using namespace std;

set<int>prime;
void getPrime(){
    for(int i=2;i<=pow(2,15);i++){
        bool ok=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                ok=0;
                break;
            }
        }
        if(ok){
            prime.insert(i);
        }
    }
}

int main(){
    getPrime();
    int x;
    while(cin>>x,x){
        int c=0;
        for(int i=2;i*2<=x;i++){
            if(prime.count(i)&&prime.count(x-i))c++;
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 1356
#include <stdio.h>

int main(void) {
	int m, f, r;
	for(; ; ) {
		scanf("%d%d%d", &m, &f, &r);
		if(m==-1 && f==-1 && r==-1) break;
		if(m==-1 || f==-1) printf("F\n");
		else {
			if(m+f>=80) printf("A\n");
			else {
				if(m+f>=65) printf("B\n");
				else {
					if(m+f>=50) printf("C\n");
					else {
						if(m+f>=30 && r>=50) printf("C\n");
						else if(m+f>=30 && r<50) printf("D\n");
						else if(m+f<30) printf("F\n");
					}
				}
			}
		}
	}
	
	return 0;
}


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

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];

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

    bool ans = true;
    rep(i, n - 1) {
        if (a[i] == a[i + 1]) {
            ans = false;
            break;
        }
    }
    if (ans) cout << "YES"<<endl;
    else cout << "NO"<<endl;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;



int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int &x: a) cin >> x;
    int x = 1;
    int ans = 0;
    for(int y: a){
        if(x == y){
            x++;
            ans++;
        }
    }
    if(ans){
        cout << n-ans << "\n";
    }
    else{
        printf("-1\n");
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ll N, Y;
  cin >> N >> Y;

  REP(i, 0, N + 1) REP(j, 0, N + 1) {
    ll k = N - i - j;
    if(k >= 0) {
      if(10000 * i + 5000 * j + 1000 * k == Y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


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

map<string,int>m;
int main() {
    int maxi=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        m[str]++;
        if(m[str]>maxi)
            maxi=m[str];
    }
    vector<string>ans;
    for(auto i: m){
        if(i.second==maxi)
            ans.push_back(i.first);
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++)
        cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int maxx = 0;
    for (int i = 1; i <= n; i++) {
        int res = i * i;
        if (res <= n) {
            maxx = i;
        }
        else
            break;
    }
    cout << maxx * maxx << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e3 + 5, M = 8200;
ll i,j,n,b,m,x,msk,ans,pre,cur;
ll a[N], mask[N];
ll dp[3][M];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    
    rep(i,1,m + 1){
        cin>>a[i]>>b;
        msk = 0;
        
        rep(j,0,b){
            cin>>x;
            msk |= modexp(2,x - 1);
        }
        mask[i] = msk;
    }
    
    rep(i,0,3) rep(j,0,M) dp[i][j] = MAX;
    dp[0][0] = 0;
    
    for(i = 1;i <= m;i += 1){
        cur = i & 1;
        pre = 1 - cur;
        
        //not taking the current key
        for(j = 0;j < M;j += 1) dp[cur][j] = dp[pre][j];
        
        //take the current key
        for(j = 0;j < M;j += 1)
            dp[cur][j | mask[i]] = min(dp[cur][j | mask[i]], a[i] + dp[pre][j]);
    }
    
    ans = dp[cur][modexp(2,n) - 1];
    cout<<(ans == MAX ? -1 : ans);
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a[100];
    for(int i=0;i<N;i++) cin >> a[i];
    int ave=0;
    for(int i=0;i<N;i++) ave += a[i];
    ave = (int)round(ave/N);

    vector<long long int> cost(3,0);
    for(int i=0;i<N;i++){
        cost[0] += pow(a[i]-ave-1,2);
        cost[1] += pow(a[i]-ave,2);
        cost[2] += pow(a[i]-ave+1,2);
    }
    long long int k = *min_element(cost.begin(),cost.end());
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <vector>
using namespace std;

template<class T> inline string toString(T x) {
	ostringstream sout;
	sout << x;
	return sout.str();
}

int n;
string num;

void zerofill() {
	int size = num.size();
	for (int i = 0; i < n - size; i++) {
		num = "0" + num;
	}
}

void solve() {
	zerofill();
	vector<string> nums;
	nums.push_back(num);
	for (int i = 0; i < 24; i++) {
		sort(num.begin(), num.end());
		int l = atoi(num.c_str());
		sort(num.rbegin(), num.rend());
		int g = atoi(num.c_str());
		num = toString(g - l);
		zerofill();
		nums.push_back(num);
	}
	for (unsigned i = 0; i < nums.size(); i++) {
		unsigned int p;
		for (p = i + 1; p < nums.size(); p++) {
			if (nums[i] == nums[p]) {
				break;
			}
		}
		if (p != nums.size()) {
			cout << i << ' ' << atoi(nums[p].c_str()) << ' ' << p - i << endl;
			return;
		}
	}
}

int main() {
	while (cin >> num >> n, !(num == "0" && n == 0)) {
		solve();
	}
}

Measured memory_bytes: 1264
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
  string s;
  cin >> s;

  if (3 == s.size())
    reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp::Ordering;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let mut x: i32 = 0;
    
    loop {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let vec: Vec<i32> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        let (x,y) = (vec[0], vec[1]);

        if x == 0 && y == 0 {
            break;
        }
        else
        {
            if x < y {
                println!("{} {}", x ,y );
            }
            else
            {
                println!("{} {}", y ,x );
            }
        }
    }

}




Measured memory_bytes: 5028
from fractions import*;g=gcd(*map(int,input().split()));d={};i=2
while i*i<=g:
    if g%i:i+=1
    else:g//=i;d[i]=d.get(i,0)+1
if g>1:d[g]=d.get(g,0)+1
print(len(d)+1)

Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string S;cin >> S;
    bool ok = true;
    rep(i,S.size()){

        if(i % 2 == 0){
            if(!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D'))ok = false;
        }
        else{
            if(!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D'))ok = false;
        }
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <stdio.h>

#define SIZE 20

int main()
{
  int cnt;
  int N, M;
  int A[SIZE] = {0,};
  int B[SIZE] = {0,};
  int C;
  int i,j;
  int result = 0;
  int ok = 0;

  cnt = scanf("%d %d %d", &N, &M, &C);

  for (i=0; i<M; i++) {
    cnt = scanf("%d", &B[i]);
  }
  for (j=0; j<N; j++) {
    result = C;
    for (i=0; i<M; i++) {
      cnt = scanf("%d", &A[i]);
      result += A[i]*B[i];
    }
    if (result > 0) ok++;
  }

  printf("%d", ok);
  
  return 0;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int n, m, q;
ll a[100], b[100], c[100], d[100];
ll num[10];
ll dfs(int idx) {
  ll res = 0;
  if(idx == n) {
    rep(j, q) {
      if(num[b[j]] - num[a[j]] == c[j]) {
        res += d[j];
      }
    }
    return res;
  }
  int start = 1;
  if(idx != 0)
    start = num[idx - 1];
  FOR(i, start, m + 1) {
    num[idx] = i;
    chmax(res, dfs(idx + 1));
  }
  return res;
}

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

  cin >> n >> m >> q;

  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  cout << dfs(0) << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > T MAX(T a,T b){return (a>b)?a:b;}
template < typename T > T MIN(T a,T b){return (a<b)?a:b;}
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
LL readint(){
	char c=getchar();
	LL ret=0ll;
	while(!(c>='0' && c<='9')) c=getchar();
	while(c>='0' && c<='9'){
		ret=ret*10ll+(LL)(c-'0');
		c=getchar();
	}
	return ret;
}
void putint(LL v){
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10ll) putint(v/10ll);
	putchar('0'+(v%10ll));
}
const int MOD=1000000007;
int n,f[5005],CNT;
namespace DSU{
	int fa[5005],sz[5005];
	void init(){
		int i;
		for(i=0;i<n;++i) fa[i]=i,sz[i]=1;
	}
	int anc(int x){
		return fa[x]==x?x:fa[x]=anc(fa[x]);
	}
	void unite(int x,int y){
		x=anc(x);
		y=anc(y);
		if(x==y){
			++CNT;
			return;
		}
		fa[x]=y;
		sz[y]+=sz[x];
	}
}
int dp[5005];
int powM(int V,int T=MOD-2){
	int R=1;
	while(T){
		if(T&1) R=(LL)R*V%MOD;
		T>>=1;
		V=(LL)V*V%MOD;
	}
	return R;
}
int main(){
	int i,j,k,sch=1;
	n=readint();
	DSU::init();
	for(i=0;i<n;++i){
		scanf("%d",f+i);
		if(~f[i]) DSU::unite(--f[i],i);
	}
	vector < int > vs;
	for(i=0;i<n;++i){
		if(!~f[i]){
			vs.push_back(DSU::sz[DSU::anc(i)]);
			sch=(LL)sch*(n-1)%MOD;
		}
	}
	int res=(LL)CNT*sch%MOD,fac=1,invopt=powM(n-1);
	dp[0]=1;
	for(i=0;i<(int)vs.size();++i){
		res+=(LL)sch*invopt%MOD*(vs[i]-1)%MOD;
		res%=MOD;
		for(j=i+1;j>0;--j){
			dp[j]=((LL)dp[j-1]*vs[i]+(LL)dp[j]*(n-1))%MOD;
		}
		dp[0]=(LL)dp[0]*(n-1)%MOD;
	}
	for(i=2;i<=(int)vs.size();++i){
		res=(res+(LL)fac*dp[i])%MOD;
		fac=(LL)fac*i%MOD;
	}
//	printf("%d %d %d\n",res,sch,n);
	printf("%lld\n",((LL)n*sch+MOD-res)%MOD);
	return 0;
}
/*
 * 代码框架
 * 0. 计算(n-1)^k
 * 1. 实现DSU，不断加入已有的边，若碰到冗余的加边则记录环的出现。
 * 2. 对每个-1的点求得其所在连通分量的大小，丢进vector
 * 3. dp[i][j]：前i个元素中，选j个乘起来的乘积之和
 * 4. 计算阶乘，枚举环长，sigma(圆排列个数*dp)
*/

Measured memory_bytes: 3908
#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--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 3000
#define MAXT 3000

int dp[MAXN+1][MAXT+1];

int main(){
  int n,t;cin>>n>>t;
  vector<pi>ab(n);
  rep(i, n)cin>>ab[i].first>>ab[i].second;

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

  rep(i, n){
    // 配置済みの食品群をそのまま次のループへ持ち越す
    rep(j, t+1){
      if(dp[i][j]>0)dp[i+1][j]=dp[i][j];
    }
    // 着目中の食品そのものを単体で配置
    if(dp[i+1][min(t, ab[i].first)] <ab[i].second)dp[i+1][min(t, ab[i].first)] = ab[i].second;
    // 配置済みの食品群に対して着目中の食品を追加したときの値を計算
    rep(j, t){
      if(dp[i][j]>0){
        int ntime = min(t, j+ab[i].first);
        if(dp[i][ntime] < dp[i][j]+ab[i].second && dp[i+1][ntime] < dp[i][j]+ab[i].second)dp[i+1][ntime] = dp[i][j]+ab[i].second;
      }
    }
// rep(j, t+1)cout<<dp[i][j]<<' ';cout<<endl;

  }

  int result = 0;
  rep(i, t+1)result = max(result, dp[n][i]);

  cout<<result<<endl;

//  rep(i, t+1)cout<<dp[n][i]<<' ';cout<<endl;

  return 0;
}


Measured memory_bytes: 38008
#![allow(unused_imports)]
use proconio::input;
use proconio::marker::*;
const MOD: u64 = 1000000007;
fn main() {
    input!(n: usize, aa: [u64; n]);

    let mut ss = vec![0; n + 1];
    for i in 0..n {
        let idx = n - i;
        ss[idx - 1] = ss[idx] + aa[idx - 1];
        ss[idx - 1] %= MOD;
    }
    let mut sum = 0;
    for i in 0..n {
        let a = aa[i];
        let s = ss[i + 1];
        let tmp = (s * a) % MOD;
        sum += tmp;
        sum %= MOD;
    }
    println!("{}", sum);
}


Measured memory_bytes: 7192
n, k, s = map(int, input().split())

for i in range(n):
    if k == 0:
        if s-1 > 0:
            print(s-1, end=' ')
        else:
            print(s+1, end=' ')
    else:
        print(s, end=' ')
        k -= 1
print()
        


Measured memory_bytes: 9324