akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  static String s;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    // String[] in = br.readLine().split(" ");
    s = br.readLine();

    br.close();

    int ans = 1;
    if (s.equals("RRR")) {
      ans = 3;
    } else if (s.substring(0, 2).equals("RR") || s.substring(1, 3).equals("RR")) {
      ans = 2;
    } else if (s.equals("SSS")) {
      ans = 0;
    }

    out.println(ans);

    out.flush();
  }
}


Measured memory_bytes: 32592
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Two Switches
	var A, B, C, D int
	fmt.Scanf("%d %d %d %d", &A, &B, &C, &D)

	ans := math.Min(float64(B), float64(D)) - math.Max(float64(A), float64(C))
	if ans >= 0 {
		fmt.Println(ans)
	} else {
		fmt.Println("0")
	}
}


Measured memory_bytes: 1840
#include<stdio.h>
 
void counting_sort(int);
int C[2000001], A[2000001],B[2000001];
int n;
 
main(){
  
  int max=0;
  int i,j;
   
  scanf("%d",&n);
  for(i=1; i <= n; i++){
    scanf("%d",&A[i]);
    if(max < A[i])
      max = A[i];
  }
   
  counting_sort(max);
   
  for(i=1; i<=n; i++){
    printf("%d",B[i]);
    if((i>0) && (i<n))
      printf(" ");
  }
  printf("\n");
   
  return 0;
}
 
 
void counting_sort(int k){
  int i,j;
   
  for(i=0; i <= k; i++){
    C[i] = 0;
  }
  for(j=1; j <= n; j++){
    C[A[j]] = C[A[j]] + 1;
  }
  for(i=1; i <= k; i++){
    C[i] = C[i] + C[i-1];
  }
  for(j=n; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
}

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

int main(){
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if(s<t) cout << "Yes";
	else cout << "No";
	return 0;
}


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

public class Main {

	private static int N;
	private static int[] A;

	public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        N = Integer.parseInt(br.readLine());
 
        String[] arrays = br.readLine().split(" ");
        A = new int[N];
        for (int i = 0, idx = 0; i < arrays.length; i++) {
            if(arrays[i].length() == 0) continue;
            A[idx++] = Integer.parseInt(arrays[i].trim());
        }
		// 挿入ソート
		for (int i = 0; i < N; i++) {
			for (int j = i; j >= 1 && A[j] < A[j - 1]; j--) {
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
			}
			System.out.print(A[0]);
			for (int j = 1; j < N; j++) {
				System.out.print(" " + A[j]);
			}
			System.out.println("");
		}

	}
}

Measured memory_bytes: 23800
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] a = Console.ReadLine().Split(" ");
        string[] b = Console.ReadLine().Split(" ");
        string t = Console.ReadLine();
        if (Math.Abs(long.Parse(b[0]) - long.Parse(a[0])) <= (long.Parse(a[1]) - long.Parse(b[1])) * long.Parse(t))
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 27472
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let input: Vec<char> = read::<String>().chars().collect();
    let a: i16 = input[0] as i16 - 48;
    let b: i16 = input[1] as i16 - 48;
    let c: i16 = input[2] as i16 - 48;
    let d: i16 = input[3] as i16 - 48;
    let mut ans: [i16; 8] = [0; 8];

    // A ? B ? C ? D
    ans[0] = a + b + c + d;
    if ans[0] == 7 {
        println!("{}+{}+{}+{}=7", a, b, c, d);
        return;
    }
    ans[1] = a + b + c - d;
    if ans[1] == 7 {
        println!("{}+{}+{}-{}=7", a, b, c, d);
        return;
    }
    ans[2] = a + b - c + d;
    if ans[2] == 7 {
        println!("{}+{}-{}+{}=7", a, b, c, d);
        return;
    }
    ans[3] = a + b - c - d;
    if ans[3] == 7 {
        println!("{}+{}-{}-{}=7", a, b, c, d);
        return;
    }
    ans[4] = a - b + c + d;
    if ans[4] == 7 {
        println!("{}-{}+{}+{}=7", a, b, c, d);
        return;
    }
    ans[5] = a - b + c - d;
    if ans[5] == 7 {
        println!("{}-{}+{}-{}=7", a, b, c, d);
        return;
    }
    ans[6] = a - b - c + d;
    if ans[6] == 7 {
        println!("{}-{}-{}+{}=7", a, b, c, d);
        return;
    }
    ans[7] = a - b - c - d;
    if ans[7] == 7 {
        println!("{}-{}-{}-{}=7", a, b, c, d);
        return;
    }
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong A, B, C, K;
  cin >> A >> B >> C >> K;

  for (int i = 0; i <= K; i++) {
    for (int j = 0; j + i <= K; j++) {
      for (int k = 0; i + j + k <= K; k++) {
        llong a = A * pow(2, i);
        llong b = B * pow(2, j);
        llong c = C * pow(2, k);
        if (a < b && b < c) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<string>
using namespace std;
int main(){
	double a[10],n,m;
	char z;
	while(cin>>a[0]){
		double h=a[0];
		for(int i=1;i<10;i++){
			cin>>z>>a[i];
			h+=a[i];
		}
		cin>>z>>n>>z>>m;
		h=h*n/(n+m);
		int i=0,w=0;
		while(true){
			if(w>=h)
				break;
			w+=a[i];
			i++;
		}
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>

#define MAX 100
#define WHITE 0
#define BLACK 1
#define GRAY 2
#define INF 1000000

void bfs();
int empty();
void enqueue(int);
int dequeue();

int num, time, head, tail, inum;
int graph[MAX][MAX];
int dis[MAX];
int color[MAX];
int Q[MAX];

int main(){

  int i, j, jnum, line;

  scanf("%d", &num);

  for(i = 0; i < num; i++){

    for(j = 0; j < num; j++){

      graph[i][j] = 0;

    }

    scanf("%d %d", &inum, &jnum);

    for(j = 0; j < jnum; j++){

      scanf("%d", &line);

      graph[inum - 1][line - 1] = 1;

    }

  }

  bfs(0);
  
  for(i = 0; i < num; i++){

    if(dis[i] == INF)
      printf("%d %d\n", (i + 1), -1);

    else
      printf("%d %d\n", (i + 1), dis[i]);

  }

  return 0;

}

void bfs(int s){

  int u, v;

  for(u = 0; u < num; u++){

    color[u] = WHITE;

    dis[u] = INF;

  }

  dis[s] = 0;

  enqueue(s);

  while(empty() == 0){

    u = dequeue();

    for(v = 0; v < num; v++){

      if(graph[u][v] == 0)
	continue;

      if(dis[v] != INF)
	continue;

      dis[v] = dis[u] + 1;

      enqueue(v);

    }

  }

}


int empty(){

  if(head == tail)
    return 1;

  else
    return 0;

}

void enqueue(int data){

  Q[tail] = data;

  if(tail == MAX) 
    tail = 0;
  else
    tail++;

}

int dequeue(){

  int data;

  data = Q[head];

  if(head == MAX) 
    head = 0;

  else
    head++;

  return data;

}

Measured memory_bytes: 636
#include <stdio.h>

#define INF 1e18

long long llabs(long long a){return a >= 0 ? a : -a;}

int main()
{
    int n,i,j;
    long long a,b[200001] = {0},min = INF;

    scanf("%d",&n);
    for (i = 0; i < n; i++)
    {
        scanf("%lld",&a);
        b[i + 1] = b[i] + a;
    }
    for (i = 1; i <= n; i++)
    {
        if(llabs(b[n] - b[i] * 2) < min)min = llabs(b[n] - b[i] * 2);
    }

    printf("%lld ",min);
}

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

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

	bool e[26];

	for (int i = 0; i < 26; i++)
	{
		e[i] = false;
	}
	for (int i = 0; i < s.size(); i++)
	{
		e[s[i] - 97] = true;
	}
	int c = -1;
	for (int i = 0; i < 26; i++)
	{
		if (!e[i])
		{
			c = i;
			break;
		}
	}
	if (c == -1) {
		cout << "None" << endl;
	}
	else {
		cout << (char)(c + 'a') << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,b;
int main()
{scanf("%d%d%d",&n,&a,&b);printf("%d\n",(n-a)%b);return 0;}

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



int main(){
    int N,T;
    cin >> N >> T;
    vector<int> cost(N);
    vector<int> time(N);
    for(int i = 0;i<N;i++){
        cin >> cost.at(i);
        cin >> time.at(i);
    }
    int smallcost = 99999;
    int ans = 0;

    for(int j = 0;j<N;j++){
        if(time.at(j) <= T){
            if(smallcost >= cost.at(j)){
                ans = j+1;
                smallcost = cost.at(j);
            }
        }
    }
	if(ans != 0){
    	cout << smallcost << endl;
    }
  	else{
    	cout << "TLE" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int md = 1e9+7;
int d, sz, ac;
long long dp[105];
string s;
int main(){
	cin >> s >> d;
	rep(i,s.size()){
		long long tmp[105] = {};
		rep(j,d) rep(k,10) (tmp[(j+k)%d] += dp[j]) %= md;
		rep(j,s[i]-'0') (tmp[(ac+j)%d] += 1) %= md;
		rep(j,d) dp[j] = tmp[j];
		ac += s[i]-'0';
	}
	printf("%lld\n", (dp[0] + (ac%d == 0) - 1 + md) % md);
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;
//--------------------

int main() {
	double res;
	double r1, r2; cin >> r1 >> r2;

	res = (r1 * r2) / (r1 + r2);
	
	cout << setprecision(20) << res << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a, b;
    char c1;
    string s;
    cin>> a;
    cin>> s;
    cin >> b;
    c1 = s[b-1];
    for (int i = 0; i< s.length(); i++){
        if(s[i] ==c1 ){
            cout << s[i];
        }
        else {
            cout << "*";
        }
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
counter = 0
roop_flag = True
while roop_flag:
    for i in range(N):
        if a[i] % 2 != 0:
            roop_flag = False
            break
        else:
            a[i] = a[i]/2
    else:
        counter += 1

print(counter)

Measured memory_bytes: 3064
open System

[<EntryPoint>]
let main _ =
    let [| n; m; x; |] = stdin.ReadLine().Split() |> Array.map int
    let a = stdin.ReadLine().Split() |> Array.map int
    let rec solve current isAscend cost =
        if current = 0 || current = n then
            cost
        else
            let cost = if Array.exists (fun x -> x = current) a then cost + 1 else cost
            if isAscend then
                solve (current + 1) isAscend cost
            else
                solve (current - 1) isAscend cost

    let ascendResult = solve x true 0
    let descendResult = solve x false 0
    min ascendResult descendResult |> stdout.WriteLine
    0


Measured memory_bytes: 11220
#include<stdio.h>
#include <string.h>
int isPrime(int x){
	int i;
	if(x<2) return 0;
	else if(x==2) return 1;
	if(x%2==0) return 0;
	for(i=3;i*i<=x;i+=2){
		if(x%i==0) return 0;
	}
	return 1;
}
int p,cnt,cnt2,food;
int n,d=0,g,kakaku[31],flag,youso[1000002]={0};
int main()
{
	scanf("%d %d",&n,&p);
	while(1){
		//memset(youso, 0, sizeof(youso));
		for(int i=0;i<p+1;i++){
			youso[i]=0;
		}
		if(n==0&&p==0){
			break;
		}
		for(cnt=1;cnt<=n;cnt++){
			scanf("%d",&food);
			youso[food]=1;
			kakaku[cnt]=food;
		}
		for(cnt=0;cnt<=p;cnt++){
			if(youso[cnt]==1){
				for(cnt2=1;cnt2<=n;cnt2++){
					if(cnt+kakaku[cnt2]<=p){
						youso[cnt+kakaku[cnt2]]=1;
					}
				}
			}
		}
		flag=0;
		for(cnt=p;cnt>=0;cnt--){
			if(youso[cnt]==1){
				g=cnt;
				d=isPrime(g);
				if(d==1){
					flag=1;
					d=cnt;
					printf("%d\n",d);
					break;
				}
			}
		}
		if(flag==0){
			printf("NA\n");
		}
		d=0;
		flag=0;
		
		scanf("%d %d",&n,&p);
	}
	return 0;
}

Measured memory_bytes: 6504
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ll int data[10000];
	ll int tmp;
	ll int cnt = 0;
	int n,m;
	cin >> n;
	REP(i,n) cin >> data[i];
	cin >> m;
	REP(i,m){
		ll int tmp;
		cin >> tmp;
		bool flag = false;
		REP(j,n){
			if(data[j]==tmp){
				flag = true;
				break;
			}
		}
		if(flag) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1240
#include <cstdio>
#include <cmath>

#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <tuple>
#include <string>

using namespace std;

#define MAX(A, B)	((A) > (B) ? (A) : (B))
#define MIN(A, B)	((A) < (B) ? (A) : (B))

bool map[55][55];

int main(int argc, char const *argv[]) {
	int h, w;
	cin >> h >> w;

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

	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			char x;
			cin >> x;
			if (x == '#') map[i][j] = true;
		}
	}

	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			if (map[i][j]) cout << '#';
			else {
				int count = 0;
				count += map[i-1][j-1];
				count += map[i-1][j];
				count += map[i-1][j+1];
				count += map[i][j-1];
				count += map[i][j+1];
				count += map[i+1][j-1];
				count += map[i+1][j];
				count += map[i+1][j+1];
				cout << count;
			}
		}
		cout << endl;
	}
}

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

int main() {
  int n;
  cin >> n;
  
  vector<pair<float,string>> xu(n);
  for (int i=0;i<n;i++){
    cin >> xu.at(i).first >> xu.at(i).second;
  }
  
  float sum = 0;
  
  for (int i=0;i<n; i++){
    if (xu.at(i).second == "JPY") sum+=xu.at(i).first;
    else sum += xu.at(i).first*380000.0;
  }
  
  
  cout << sum << endl;
}


Measured memory_bytes: 256
a, b, n = map(int, input().split())

if b == 1:
    r = [0]
else:
    i = 0
    r = [int((a*n)/b)-a*int(n/b)]
    while b*i-1 <= n:
        r.append(int((a*(b*i-1))/b)-a*int((b*i-1)/b))
        i += 1
print(max(r))

Measured memory_bytes: 61668
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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

    cout << t << s << endl;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // input S T
        // 長さ 3 の文字列 S,T について、順番通りで一致する文字が何文字あるか出力せよ
        Scanner sc = new Scanner(System.in);
        String strS = sc.nextLine();
        String strT = sc.nextLine();
        int retNum = 0;
        if(strS.substring(0,1).equals(strT.substring(0,1))){
            retNum++;
        }
        if(strS.substring(1,2).equals(strT.substring(1,2))){
            retNum++;
        }
        if(strS.substring(2,3).equals(strT.substring(2,3))){
            retNum++;
        }
        System.out.println(retNum);
    }
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    double r;
    cin>>r;
    cout<<r*r*M_PI<<" "<<2*r*M_PI<<endl;
    return 0;
}


Measured memory_bytes: 3300
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] nums = new int[10];
		
		while(sc.hasNext()){
			String s = sc.next();
		
			for(int i=0; i<10; i++)
				nums[i] = Integer.parseInt("" + s.charAt(i));
			
			for(int i=0; i<9; i++){
				for(int j=0; j<9-i;	j++){
					nums[j] = (nums[j] + nums[j+1])%10;	
				}
			}
		
			System.out.println(nums[0]);
		}
	
	}
}

Measured memory_bytes: 17284
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100100
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll N;
    cin >> N;
    ll a[MAX], b[MAX], c[MAX];
    ll i;
    ll dp[MAX][3]={};
    
    for(i=0; i<N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    
    for(i=1; i<=N; i++) {
        
        dp[i][0]=max(dp[i][0], dp[i-1][1]+a[i-1]);
        dp[i][0]=max(dp[i][0], dp[i-1][2]+a[i-1]);
        
        dp[i][1]=max(dp[i][1], dp[i-1][2]+b[i-1]);
        dp[i][1]=max(dp[i][1], dp[i-1][0]+b[i-1]);
        
        dp[i][2]=max(dp[i][2], dp[i-1][0]+c[i-1]);
        dp[i][2]=max(dp[i][2], dp[i-1][1]+c[i-1]);
        
    }
    
    ll ans=max(dp[N][0], max(dp[N][1], dp[N][2]));
    pr(ans);
    
}













Measured memory_bytes: 4992
#include <iostream>
#include <string>

using namespace std;

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

    int max_val = 0;
    int max_cnt = 0;
    for (int i=1; i<=N; ++i) {
        int cnt = 0;
        int j = i;
        while(j%2==0) {
            j /= 2;
            ++cnt;
        }
        if (cnt >= max_cnt) {
            if (i > max_val) {
                max_val = i;
                max_cnt = cnt;
            }
        }
    }

    cout << max_val << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;
int h[26], len;
char s[200010];
LL ans;

int main(){
	int i;
	scanf("%s", s + 1); len = strlen(s + 1);
	for(i = 1; i <= len; ++i)
		h[s[i]-'a']++;
	ans = (LL) len * (len - 1) / 2 + 1ll;
	for(i = 0; i < 26; ++i)
		ans -= (LL) h[i] * (h[i] - 1) / 2;
	printf("%lld\n", ans);
	return 0;
} 

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define REP(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;

ll pcnt[3], plim[3];
string S[10];
int cum[11][1001];
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    
    rep(i, H){
        cin >> S[i];
        rep(j, W){
            cum[i][j + 1] = cum[i][j] + S[i][j] - '0';
            //cout << cum[i][j + 1];
        }
        //cout << endl;
    }
    int a0 = H + W;
    rep(bit, 1 << (H - 1)){
        vector<int> v;
        v.push_back(0);
        
        rep(k, H - 1){
            if (bit & (1 << k)){
                v.push_back(k + 1);
            }
        }
        v.push_back(H);
        int ans = v.size() - 2;
        //fprintf(stderr, "bit = %d (%d), ", bit, v.size());
        //rep(ii, v.size())fprintf(stderr, "v[%d] = %d, ", ii, v[ii]);
        //fprintf(stderr, "\n");
        int prev_split = 0; 
        rep(j, W){
            rep(ii, v.size() - 1){
                int sum = 0;
                for (int iii = v[ii]; iii < v[ii + 1]; iii++){
                    sum += cum[iii][j + 1] - cum[iii][prev_split];
                }
                if (sum > K){
                    if (prev_split == j){
                        goto end;
                    } else {
                        goto next;
                    }
                }
            }
            continue;
            next:
            prev_split = j;
            //fprintf(stderr, "  prev_split = %d\n", j);
            ans++;
        }
        //fprintf(stderr, "ans = %d\n", ans);
        chmin(a0, ans);
        end:
        ;
    }
    cout << a0;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
ans = 0
ansk = 0
tmp = -1
while tmp < N:
    tmp += 1
    if ans > 0:
        tmp += ans-1
        ans = 0
        continue
    for j in range(tmp+1,N):
            if H[j-1] < H[j]:
                ansk = max(ansk,ans)
                break
            ans += 1
            if j == N-1:
                ansk = max(ansk,ans)
                tmp = N
                break
print(ansk)

Measured memory_bytes: 63856
#include <iostream>
#include <utility>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 2000000000
#define REP(i,b,n) for(int i = (b); i < n; i++)
#define rREP(i,b,n) for(int i = n; i >= (b); i--)
using namespace std;
using ll = long long;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string lowercase = "abcdefghijklmnopqrstuvwxyz";
const string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gcd(int a, int b){return b ? gcd(b, a % b): a;}

bool is_prime(int p){
    if(p==1) return false;
    REP(i,2,p){
        if(p%i==0) return false;
    }
    return true;
}

int main()
{
    int N;
    cin >> N;
    for(int num=11; num<=55555; num+=10){
        if(is_prime(num)) {
            printf("%d ", num);
            N--;
        }
        if(!N) break;
    }
    cout << endl;
    return 0;
}


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

#include <string>
#include <sstream>

namespace patch
{
    template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
}

#include <iostream>
int main(){
	int i,j;
	string s;
while(cin>>i>>j){
	cout<<patch::to_string(i+j).length()<<endl;
}
    return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
#define max 100
#define inf 100000000
using namespace std;
int dijkustra(int s, int e);
int n,m;
int G[max][max];


int main(){
  int start,goal;
  int a,b,c,d,money,pay,go,back;
  cin >>n>>m;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) G[i][j]=inf;}

  for(int i=0;i<m;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    a--;b--;
    //  cout << "hoge\n";
    G[a][b]=c;
    G[b][a]=d;
  }
  
  scanf("%d,%d,%d,%d",&start,&goal,&money,&pay);

  go = dijkustra(start-1,goal-1);
  back = dijkustra(goal-1,start-1);
 
 cout <<money-pay-go-back<<endl; 
    return 0;
}

int dijkustra(int s,int g){
  int mindist[max];
  bool used[max];
  int qur,value,next;

  for(int i=0;i<n;i++){
    mindist[i]=inf;
    used[i]=false;
  }

  mindist[s]=0;

  while(1){

    /* for(int i=0;i<n;i++)
      cout<<mindist[i]<<" ";     
      cout <<endl;*/


    value=inf;
    for(int i=0;i<n;i++){
      if(value > mindist[i]  && used[i] == false){
	value=mindist[i];
	qur=i;}
    }
    //    cout <<value<<endl;
    used[qur]=true;
    if(value==inf)break;

    for(int j=0;j<n;j++){
      if(G[qur][j]!=inf){
	next = j;
	if(mindist[next] > mindist[qur] + G[qur][next])
	  mindist[next] = mindist[qur] + G[qur][next];
 	}
    }

  }
  return mindist[g];
}

Measured memory_bytes: 1248
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1e16; //10^9+7

int m, st, go;
ll a[100002], b[100002], u[10002], v[100002];


int n;//number of element
const ll MAX_N = 100002;
vector<pair<ll, ll> > g[MAX_N]; //first は行き先、secondはcost　関数に入る前にiから伸びる辺をg[i]にいれておく。
ll d[MAX_N];

void dijkstra(int s){
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>> > que; //first は最短距離、secondは頂点番号
    REP(i, n + 1)d[i] = mod;
    d[s] = 0;
    que.push(make_pair(0, s));

    while(!que.empty()){
        auto p = que.top(); que.pop();
        ll v = p.second;
        if(d[v] < p.first)continue;
        REP(i, g[v].size()){
            auto e = g[v][i];
            if(d[e.first] > d[v] + e.second){
                d[e.first] = d[v] + e.second;
                que.push(make_pair(d[e.first], e.first));
            }
        }
    }
}

vector<pair<ll, ll> > g1[MAX_N]; //first は行き先、secondはcost　関数に入る前にiから伸びる辺をg[i]にいれておく。
ll d1[MAX_N];

void dijkstra1(int s){
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>> > que; //first は最短距離、secondは頂点番号
    REP(i, n + 1)d1[i] = mod;
    d1[s] = 0;
    que.push(make_pair(0, s));

    while(!que.empty()){
        auto p = que.top(); que.pop();
        ll v = p.second;
        if(d1[v] < p.first)continue;
        REP(i, g1[v].size()){
            auto e = g1[v][i];
            if(d1[e.first] > d1[v] + e.second){
                d1[e.first] = d1[v] + e.second;
                que.push(make_pair(d1[e.first], e.first));
            }
        }
    }
}

int main(){
    cin >> n >> m >> st >> go;
    REP(i, m){
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        g[u[i]].emplace_back(make_pair(v[i], a[i]));
        g[v[i]].emplace_back(make_pair(u[i], a[i]));
        g1[u[i]].emplace_back(make_pair(v[i], b[i]));
        g1[v[i]].emplace_back(make_pair(u[i], b[i]));
    }
    dijkstra(st);
    dijkstra1(go);
    ll ans = 1e15;

    ll min_cost[100002];
    REP(i, 100002)min_cost[i] = d[i] + d1[i];
    for(int i = n - 1; i >= 1; i--){
        min_cost[i] = min(min_cost[i], min_cost[i + 1]);
    }
    rep(i, 1, n + 1){
        print(ans - min_cost[i]);
    }
    return 0;
}

Measured memory_bytes: 21572
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  for (int i = 0; i < N - K; ++i) {
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>

using namespace std;

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

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

    int B[M];
    REP(0, i, M) {
        cin >> B[i];
    }

    int A[N][M];
    REP(0, i, N) {
        REP(0, j, M) {
            cin >> A[i][j];
        }
    }

    int cnt = 0;
    REP(0, i, N) {
        int acc = 0;

        REP(0, j, M) {
            acc += A[i][j] * B[j];
        }

        acc += C;

        if (acc > 0) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

typedef ll Weight;

struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool WarshallFloyd(const Matrix &g,Matrix &dist) {
    int n = (int)g.size();
    dist = g;
    repeat(k, n) repeat(i, n) repeat(j, n) {
        if(dist[i][k] == INF || dist[k][j] == INF) continue;
        if (dist[i][j] > dist[i][k] + dist[k][j]) {
            dist[i][j] = dist[i][k] + dist[k][j];
        }
    }
    bool negative_cycle = false;
    repeat(i,n){
        negative_cycle |= (dist[i][i] < 0);
    }
    return !negative_cycle;
}

int main(){
  int N,M;cin>>N>>M;
  Edges E;
  Matrix g(N,Array(N,INF));
  repeat(i,N){
    g[i][i]=0;
  }
  repeat(i,M){
    int a,b;
    Weight c;
    cin>>a>>b>>c;a--;b--;
    E.push_back({a,b,c});
    g[a][b]=g[b][a]=c;
  }
  Matrix d;
  WarshallFloyd(g,d);
  int ans = 0;
  repeat(i,M){
    bool isok=true;
    repeat(u,N){
      repeat(v,N){
        isok &= d[u][v]<d[u][E[i].src]+E[i].weight+d[E[i].dst][v];
        isok &= d[u][v]<d[v][E[i].src]+E[i].weight+d[E[i].dst][u];
      }
    }
    if(isok)ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 l, r;
    std::cin >> l >> r;
    std::vector<std::vector<i64>> t(2019, std::vector<i64>(2019));
    i64 min = std::numeric_limits<i64>::max();
    for (int i = 0; i < 2019; i++) for (int j = 0; j < 2019; j++) {
        t[i][j] = i * j % 2019;
        min = std::min(min, t[i][j]);
    }

    if (r - l < 2018) {
        min = std::numeric_limits<i64>::max();
        for (int i = l; i <= r; i++) {
            for (int j = i + 1; j <= r; j++) {
                min = std::min(min, t[i % 2019][j % 2019]);
            }
        }
    }

    std::cout << min << std::endl;

    return 0;
}


Measured memory_bytes: 32128
#include<stdio.h>
#define MAX 10000
typedef struct{int parent,left,right;}Node;
 
Node T[MAX];
int n,D[MAX],H[MAX];
 
void setDepth(int u,int d){
  if(u == EOF)return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
 
int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left != EOF) h1 = setHeight(T[u].left) + 1;
  if(T[u].right != EOF)h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2); 
}
 
int getSibling(int u){
  if(T[u].parent == EOF)return EOF;
  if(T[T[u].parent].left != u && T[T[u].parent].left != EOF)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != EOF)
    return T[T[u].parent].right;
  return EOF;
}
 
void print(int u){
  int deg;
   
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getSibling(u));
  deg = 0;
  if(T[u].left != EOF)deg++;
  if(T[u].right != EOF)deg++;
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
  if(T[u].parent == EOF)printf("root\n");
  else if(T[u].left == EOF && T[u].right == EOF)printf("leaf\n");
  else printf("internal node\n");
}
 
int main(){
  int i,v,l,r,root = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].parent = EOF;
   
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != EOF)T[l].parent = v;
    if(r != EOF)T[r].parent = v;
  }
   
  for(i=0;i<n;i++) if(T[i].parent == EOF)root = i;
   
  setDepth(root,0);
  setHeight(root);
   
  for(i=0;i<n;i++) print(i);
   
  return 0;
}



Measured memory_bytes: 2052
N = int(raw_input())
A = map(int, raw_input().split())

x_occurance = {}
minus = []
for i in range(N):
	p = A[i] + i
	m = i - A[i]
	x_occurance[p] = x_occurance.get(p, 0) + 1
	minus.append(m)

count = 0
for i in range(N):
	count += x_occurance.get(minus[i], 0) 

print count

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

int N;

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

int main()
{
    scanf("%d",&N);

    if(N == 3)
    {
        printf("2 5 63\n");
        return 0;
    }
    if(N == 4)
    {
        printf("2 5 20 63\n");
        return 0;
    }
    if(N == 5)
    {
        printf("2 4 3 9 6\n");
        return 0;
    }
    vector<int> ans;
    int cnt = 0;
    for(int i = 0; i < N; i++)
    {
        if(i % 8 == 0)ans.push_back(6 + cnt * 12);
        if(i % 8 == 1)
        {
            ans.pop_back();
            ans.push_back(2 + cnt * 12);
            ans.push_back(4 + cnt * 12);
        }
        if(i % 8 == 2)ans.push_back(6 + cnt * 12);
        if(i % 8 == 3)
        {
            ans.pop_back();
            ans.push_back(8 + cnt * 12);
            ans.push_back(10 + cnt * 12);
        }
        if(i % 8 == 4)ans.push_back(6 + cnt * 12);
        if(i % 8 == 5)
        {
            ans.pop_back();
            ans.push_back(3 + cnt * 12);
            ans.push_back(9 + cnt * 12);
        }
        if(i % 8 == 6)ans.push_back(6 + cnt * 12);
        if(i % 8 == 7)
        {
            ans.push_back(12 + cnt * 12);
            cnt++;
        }
    }

    for(int i = 0; i < N; i++)
    {
        printf("%d",ans[i]);
        if(i != N - 1)printf(" ");
    }printf("\n");

    return 0;
}


Measured memory_bytes: 512
import sys,collections,math,random,fractions;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a,b,c,d = Is()
mc = b//c - (a-1)//c
md = b//d - (a-1)//d
mincom = lcm(c,d)
mcd = b//(mincom) - (a-1)//(mincom)
ans = b-a+1 - (mc + md - mcd)
#print(mc,md,mcd)
print(ans)

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wgraph = std::vector<std::vector<std::pair<ll,ll>>>;

using namespace std;

int main() {
    ll N,M,R;
    cin >> N >> M >> R;
    vector<ll> r(R);
    for(int i = 0; i < R; i++){
        ll tmp = 0;
        cin >> tmp;
        tmp--;
        r[i] = tmp;
    }
    sort(r.begin(),r.end());
    ll D1[N][N];
    for(int yi = 0; yi < N; yi++){
        for(int xi = 0; xi < N; xi++){
                D1[yi][xi] = 1ll << 50;
        }
    }
    for(ll i = 0; i < M; i++){
        ll A,B,C;
        cin >> A >> B >> C;
        A--;B--;
        D1[A][B] = C;
        D1[B][A] = C;
    }

    for(int i = 0; i <N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                D1[j][k] = min(D1[j][k], D1[j][i] + D1[i][k]);
                D1[k][j] = D1[j][k];
            }
        }
    }
    ll minCost = 1ll << 50;
    ll rr = 1;
    for(int i = 1; i <= R; i++){
        rr *= i;
    }
    for(int i = 0; i < rr; i++){
        ll tmp = 0;
        for(int i = 0; i < R - 1; i++){
            tmp += D1[r[i]][r[i + 1]];
        }
        minCost = min(minCost,tmp);
        //for(auto i : r) cout << i << " ";
        //cout << endl;
        next_permutation(r.begin(),r.end());
    }
    cout << minCost << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
using namespace std;

const double PI=acos(-1);

int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0, max = cnt;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'I') cnt++;
        else cnt--;
        max = std::max(max, cnt);
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), C = getint();
	const int mod = 1e9 + 7;

	int AB[401][401];
	rep1(i, 400) {
		AB[i][0] = 1;
		rep(j, 400) {
			AB[i][j + 1] = ll(AB[i][j]) * i % mod;
		}
	}
	rep(j, 401) {
		AB[0][j] = 0;
		rep(i, 400) {
			AB[i + 1][j] = (AB[i + 1][j] + AB[i][j]) % mod;
		}
	}

	ll dp[2][401] = {};
	dp[0][0] = 1;
	int a[400];
	rep(i, N) a[i] = getint();
	rep(i, N) {
		auto mae = dp[i & 1];
		auto tugi = dp[!(i & 1)];
		int b = getint();
		auto A = AB[a[i] - 1];
		auto B = AB[b];

		for (int j = C; j >= 0; j--) {
			tugi[j] = mae[j] * (b - a[i] + 1) % mod;
		}

		rep1(k, C) {
			int K = B[k] - A[k];
			rep(j, C - k + 1) {
				tugi[j + k] += mae[j] * K % mod;
			}
			tugi[k] %= mod;
		}
	}

	printf("%lld", (dp[N & 1][C] % mod + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>



int main() {
    int long long n,i,d=0,e=0,m=100000000000;
    scanf("%lld ",&n);
    int long long a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld ",&a[i]);
        
     if(a[i]%2==0)
         d++;
     while(a[i]%2==0)
        {
                e++;
                a[i]=a[i]/2;
                
            
            
            
                
          
        }
        m=m>e?e:m;
        e=0;
    }
    if(d==n)
    {
     printf("%lld",m);
    }
    else
        printf("0");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cassert>
using namespace std;

const int N = 55, MOD = 1000000007;
int n;
char a[2][N];
int64_t dp[N][3][3];

int64_t go(int ix,int x,int y) {
    assert(x < 3 && y < 3);
    if(ix >= n) return 1;
    if(dp[ix][x][y]) return dp[ix][x][y];
    int64_t ans = 0;
    if(a[0][ix] == a[1][ix]) {
        if(x != y) {
            ans = go(ix+1,3-x-y,3-x-y);
        } else {
            for(int i=0;i<3;i++) if(i != x) {
                ans += go(ix+1,i,i); ans %= MOD;
            }
        }
    } else {
        if(x != y) {
            ans += go(ix+2,y,3-x-y); ans %= MOD;
            ans += go(ix+2,3-x-y,x); ans %= MOD;
            ans += go(ix+2,y,x); ans %= MOD;
        } else {
            for(int i=0;i<3;i++) if(i == x) {
                int _x = (i+1)%3, _y = (i+2)%3;
                ans += go(ix+2,_x,_y); ans %= MOD;
                ans += go(ix+2,_y,_x); ans %= MOD;
            }
        }
    }
    dp[ix][x][y] = ans;
    return ans;
}

int main() {
    cin >> n;
    cin >> a[0] >> a[1];
    int64_t ans = 0;
    if(a[0][0] == a[1][0]) {
        for(int i=0;i<3;i++) {
            ans += go(1,i,i); ans %= MOD;
        }
    } else {
        for(int i=0;i<3;i++) {
            int _x = i, _y = (i+1)%3;
            ans += go(2,_x,_y); ans %= MOD;
            ans += go(2,_y,_x); ans %= MOD;
        }
    }
    cout << ans;
}

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

const int maxN = 1e5 + 10, mod = 998244353, lim = 1 << 10;

int n, m;
int ans[maxN + 1], g[maxN + 1], pw[maxN + 1];
int flag[maxN + 1], t[maxN + 1], s[maxN + 1];
bool vis[maxN + 1];

vector<int> nxt[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int read()
{
	int num = 0, f = 1;
	char ch = getchar();
	while( !isdigit( ch ) ) { if(ch == '-') f = -1; ch = getchar(); }
	while( isdigit( ch ) ) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
	return num * f;
}

inline void dfs(int u)
{
	vis[u] = true;
	for(int i = 0; i < nxt[u].size(); i++) 
		if(!vis[ nxt[u][i] ]) dfs(nxt[u][i]);
	for(int i = 0; i < nxt[u].size(); i++) flag[ g[ nxt[u][i] ] ] = u;

	g[u] = 0;
	while(flag[ g[u] ] == u) g[u] ++;
}

inline void work()
{
	m = read();
	for(int i = 1; i <= n; i++) vis[i] = false, nxt[i].clear();
	for(int i = 0; i < lim; i++) flag[i] = s[i] = 0;

	for(int i = 1; i <= m; i++)
	{
		int x = read(), y = read();
		if(x > y) swap(x, y);
		nxt[x].push_back(y);
	}

	for(int i = 1; i <= n; i++)
		if(!vis[i]) dfs(i);
	
	for(int i = 1; i <= n; i++) s[ g[i] ] = ADD(s[ g[i] ], pw[i]);

	for(int i = 0; i < lim; i++) t[i] = ans[i], ans[i] = 0;
	for(int i = 0; i < lim; i++)
		for(int j = 0; j < lim; j++)
			ans[i ^ j] = ADD(ans[i ^ j], 1ll * t[i] * s[j] % mod);
}

int main()
{
	int base = 1;
	for(int i = 1; i <= 18; i++) base = 10ll * base % mod;

	n = read();
	pw[0] = 1;
	for(int i = 1; i <= n; i++) pw[i] = 1ll * base * pw[i - 1] % mod;
	
	ans[0] = 1;
	for(int i = 1; i <= 3; i++) work();

	printf("%d", ans[0]);
	return 0;
}


Measured memory_bytes: 7296
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static long f(long x)
        {
            long y = 0;
            for (int i = 1; i <= x; i++)
            {
                y += i;
            }
            return y;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var  input = Reads();
            var a= input[0];
            var b = input[1];

            Console.WriteLine(f(b-a) - b);
           

            
           
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n;
    char buf[30];

//標準入力から一行bufに格納
    fgets(buf, sizeof(buf), stdin);
    n = atoi(buf);

    // 標準出力に

    printf("%d\n", n+(n*n)+(n*n*n));

    return 0;
}

Measured memory_bytes: 1656
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

const role = ([top, back, right, left, front, bottom], d) => {
  switch (d) {
    case "N":
      [top, front, bottom, back] = [back, top, front, bottom];
      break;
    case "S":
      [top, front, bottom, back] = [front, bottom, back, top];
      break;
    case "W":
      [top, left, bottom, right] = [right, top, left, bottom];
      break;
    case "E":
      [top, left, bottom, right] = [left, bottom, right, top];
      break;
    case "R":
      [front, left, back, right] = [left, back, right, front];
      break;
  }
  return [top, back, right, left, front, bottom];
};

const cd = (d1, d2) => {
  let ret = true;
  for (let i = 0; i < 6; i++) {
    if (d1[i] !== d2[i]) {
      ret = false;
      break;
    }
  }
  return ret;
};

const cdr = (dice1, dice2) => {
  let match = false;
  for (let i = 0; i < 4; i++) {
    for (let j = 0; j < 4; j++) {
      for (let k = 0; k < 4; k++) {
        match = cd(dice1, dice2);
        if (match) break;
        dice1 = role(dice1, "R");
      }
      match = cd(dice1, dice2);
      if (match) break;
      dice1 = role(dice1, "E");
    }
    match = cd(dice1, dice2);
    if (match) break;
    dice1 = role(dice1, "N");
  }
  return match;
};

reader.on("close", () => {
  let n = lines[0] - 0;
  let match = false;
  for (let i = 1; i < n && !match; i++) {
    for (let j = i + 1; j < n + 1 && !match; j++) {
      match = cdr(lines[i].split(" "), lines[j].split(" "));
    }
  }
  console.log(match ? "No" : "Yes");
});



Measured memory_bytes: 19872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int abroad=0,pass=0;
  for(int i=0;i<n;i++){
    if(s[i]=='c'){
      cout << "No" << endl;
      continue;
    }
    if(s[i]=='a'){
      if(pass < (a+b)){
        cout << "Yes" << endl;
        pass++;
      }else{
        cout << "No" << endl; 
      }
    }
    if(s[i]=='b'){
      abroad++;
      if(pass < (a+b) && abroad <= b){
        cout << "Yes" << endl;
        pass++;
      }else{
        cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 3708
#include<iostream>
using namespace std;
int main() {
    long long x, k, d;
    cin >> x >> k >> d;
    long long a, b;
    if (x > 0) {

        if (x / d < k) {
            if ((k - x / d) % 2 == 0) {
                cout << x % d << endl;
            }
            else {
                cout << d - x % d << endl;
            }
        }
        else {
            cout << x - k * d << endl;
        }
    }
    else if (x < 0) {
        if (-x / d < k) {
            if ((k + x / d)% 2 == 0) {
                cout << -x % d << endl;
            }
            else {
                cout << d + x % d << endl;
            }
        }
        else {
            cout << -x - d * k << endl;
        }
    }
    else {
        if (k % 2 == 0) {
            cout << 0 << endl;
        }
        else {
            cout << d << endl;
        }
    }
}


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

int main(void) {
  long long n, k;
  cin >> n >> k;
  
  long long p_rem, m_rem;
  if (n % k == 0)
    cout << 0 << endl;
  else {
    p_rem = n % k;
    
    if (n >= k) {
      long long x;
      x = (n / k) + 1;
      m_rem = x * k - n;
    }
    else {
      long long y;
      y = (n / k) + 1;
      m_rem = y * k - n;
    }   
    
    cout << min(p_rem, m_rem) << endl;
  }     
  
  return 0;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,x,m;
	cin>>n>>k;
	m=0;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x>k/2){
			m+=(k-x)*2;
		}
		else{
			m+=x*2;
		}
	}
	cout<<m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    ll ans=0;
    rep(i, n) ans += d[i];
    ans = pow(ans, 2);
    rep(i, n) {
        ans -= pow(d[i], 2);
    }
    ans /= 2;
    cout << ans << endl;
}

Measured memory_bytes: 256