akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N = r.i();
        int[][] xyh = new int[N][3];
        for(int i = 0; i < N; i++) xyh[i] = r.ii();
        int x, y, h;
        {
            int j = -1;
            while(xyh[++j][2] == 0){}     
            int[] a = xyh[j];
            x = a[0];
            y = a[1];
            h = a[2];
        }
        for(int Cx = 0; Cx < 101; Cx++){
            loop: for(int Cy = 0; Cy < 101; Cy++){
                int H = Math.abs(Cx-x) + Math.abs(Cy-y) + h;
                for(int i = 0; i < N; i++){
                    int[] xyhi = xyh[i]; 
                    if(xyhi[2] != Math.max(H - Math.abs(Cx-xyhi[0]) - Math.abs(Cy-xyhi[1]), 0)) continue loop;
                }
                System.out.println(Cx + " " + Cy + " " + H);
                return;
            }
        }        
    }

    static void print(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int Int(String s){
            return Integer.parseInt(s);
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

constexpr char S = '#';
vector<string> s;
vector<vector<int>> ans;
int col = 1;

void splitcake(const int xs,const int xe,const int ys,const int ye) {
    // cerr << xs << " " << xe << " " << ys << " " << ye << endl;
    int x1 = -1;
    int y1 = -1,y2 = -1;
    for(auto y = ys; y <= ye; y++) {
        auto pos = s[y].find(S,xs);
        if (pos <= xe) {
            if (y1 == -1) y1 = y;
            else {
                y2 = y;
                break;
            }
        }
    }

    if (y2 != -1) {
        // ichigo 2 line over
        // cerr << "ysplit" << endl;
        splitcake(xs,xe,ys,y1);
        splitcake(xs,xe,y1+1,ye);
    } else {
        // ichigo 1 line
        x1 = s[y1].find(S,xs);
        auto pos = s[y1].find(S,x1+1);
        if (pos > xe) {
            // paint
            // cerr << "p" << col << endl;
            for(int y = ys; y <= ye; y++) for(int x = xs; x <= xe; x++) ans[y][x] = col;
            col++;
        } else {
            // cerr << "xsplit" << endl;
            splitcake(xs,x1,ys,ye);
            splitcake(x1+1,xe,ys,ye);
        }
    }

}

int main(void)
{
    IOS
    int h, w, k;
    cin >> h >> w >> k;
    s.resize(h);
    REP(i,h) cin >> s[i];
    ans.resize(h);
    REP(i,h) ans[i].resize(w);

    splitcake(0,w-1,0,h-1);

    for(auto v:ans) {
        REP(i,v.size()-1) cout << v[i] << " ";
        cout << v.back() << endl;
    }

    return 0;
}


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

constexpr int32_t MAX_BIT = (1ull << 10);
constexpr int32_t MAX_WEIGHT = 1e5;

int32_t dp[MAX_BIT + 1][MAX_WEIGHT + 1];

int main() {
    int32_t N;
    cin >> N;
    vector<int32_t> V(N + 1), W(N + 1);
    for (int32_t i = 1; i <= N; i++) {
        cin >> V[i] >> W[i];
//        V[i] = W[i] = i;
    }

    int32_t Q;
    cin >> Q;
    vector<int32_t> v(Q), L(Q);
    for (int32_t i = 0; i < Q; i++) {
        cin >> v[i] >> L[i];
    }

    //半分全列挙
    int32_t lb = min(N, MAX_BIT);

    //dp[i][j] := i番目のノードにおいて残り容量がjであるときの最大価値
    //1のところを初期化
    for (int32_t j = W[1]; j <= MAX_WEIGHT; j++) {
        dp[1][j] = V[1];
    }

    for (int32_t i = 2; i <= lb; i++) {
        for (int32_t j = 0; j <= MAX_WEIGHT; j++) {
            //選ばない場合
            dp[i][j] = max(dp[i][j], dp[i / 2][j]);

            //選ぶ場合
            if (j - W[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i / 2][j - W[i]] + V[i]);
            }
        }
    }

    //クエリを解く
    for (int32_t i = 0; i < Q; i++) {
        //スタート位置が基準より前だったらそのまま答えて終わり
        if (v[i] <= lb) {
            cout << dp[v[i]][L[i]] << endl;
            continue;
        }

        //そうでなかったらlbに入るまでを全探索
        vector<int32_t> curr_v, curr_w;
        int32_t node = v[i];
        for (; node > lb; node /= 2) {
            curr_v.push_back(V[node]);
            curr_w.push_back(W[node]);
        }

        int32_t ans = 0;
        int32_t max_bit = (1ull << curr_v.size());
        for (int32_t j = 0; j < max_bit; j++) {
            int32_t curr_value = 0, curr_weight = 0;
            for (int32_t k = 0; k < curr_v.size(); k++) {
                if (j & (1ull << k)) {
                    curr_value += curr_v[k];
                    curr_weight += curr_w[k];
                }
            }

            if (curr_weight > L[i]) {
                continue;
            }

            ans = max(ans, curr_value + (L[i] == curr_weight ? 0 : dp[node][L[i] - curr_weight]));
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 406152
x, y, theta = 0.0, 0.0, 90
while true
    d, angle = gets.chomp.split(",").map(&:to_i)
    break if d == 0 && angle == 0

    rad = theta / 180.0 * Math::PI
    x += d * Math.cos(rad)
    y += d * Math.sin(rad)
    theta -= angle 
end
puts x.to_i
puts y.to_i

Measured memory_bytes: 8864
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)


int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int l = max(a,c), r= min(b,d);
    if(l>r)cout << 0 << endl;
    else cout << r-l << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long result = 0;

		for(int i=1;i<=N;i++) {
			if(i%3!=0&&i%5!=0) {
				result = result+i;
			}
		}
		System.out.println(result);
	}


}



Measured memory_bytes: 35896
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    long n, x, m;
    std::cin >> n >> x >> m;
    std::vector<int> v(m, -1);
    long x1 = x, from = -1, to = -1, tmpcnt = 0;
    for(int i = 0; i <= m; ++i){
        if(i == n){
            std::cout << tmpcnt <<std::endl;
            return 0;
        }
        tmpcnt += x1;
        if(-1 == v[x1]) v[x1] = i + 1;
        else{
            from = v[x1];
            to = i + 1;
            break;
        }
        x1 = (x1 * x1) % m;
    }
    long cnt = 0;
    x1 = x;
    for(long i = 1; i < from; ++i){
        cnt += x1;
        x1 = (x1 * x1) % m;
    }
    long sum_loop = 0;
    for(long i = from; i < to; ++i){
        sum_loop += x1;
        x1 = (x1 * x1) % m;
    }
    cnt += sum_loop * ((n - from + 1) / (to - from));
    long tmp = from - 1 + ((n - from + 1) / (to - from)) * (to - from) + 1;
    for(long i = tmp; i <= n; ++i){
        cnt += x1;
        x1 = (x1 * x1) % m;
    }
    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,i;
	scanf("%d %d %d",&a,&b,&c);
	for(i=0;!(a==b&&b==c&&a==c);i++)
	{
		if(a==b&&a>c)
			c+=2;
		else if(c==b&&c>a)
			a+=2;
		else if(a==c&&a>b)
			b+=2;
		else if(a>b&&a>c)
		{
			b++;
			c++;
		}
		else if(b>a&&b>c)
		{
			a++;
			c++;	
		}
		else
		{
			a++;
			b++;	
		}	
	}
	printf("%d",i);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int ans = 0;
    if (n % x == 0)
    {
        ans = n / x * t;
    }
    else
    {
        ans = (n / x + 1) * t;
    }
    cout << ans << endl;
    
}

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

int main(){
  int H ;
  int N ;
  int A ;
  int count=0;
  int i =0;
  cin >> H ;
  cin >> N ;
  
  while(i<N){
    cin >> A;
    count=count+A;
    i++;
    A=0;
  }
  if(count>=H){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var ABC = new ABC { A = input[1], B = input[2], C = input[3] };

            var S = new string[N + 1];
            for (int i = 0; i < N; i++) S[i] = Console.ReadLine();
            S[N] = string.Empty;

            var path = new List<char>();

            for (int i = 0; i < N; i++)
            {
                var c = Set(ABC, S[i], S[i + 1]);
                if (c == null)
                {
                    Console.WriteLine("No");
                    return;
                }
                path.Add(c.Value);
            }

            Console.WriteLine("Yes");
            path.ForEach(c => Console.WriteLine(c));
        }

        static char? Set(ABC abc, string s1, string s2)
        {
            if ((s1 == "AB" && abc.A == 0 && abc.B == 0)
               || (s1 == "AC" && abc.A == 0 && abc.C == 0)
               || (s1 == "BC" && abc.B == 0 && abc.C == 0))
            {
                return null;
            }

            if (s1 == "AB")
            {
                if (abc.A == 0) return abc.Add(1, -1, 0);
                else if (abc.B == 0 || s2.Contains("B")) return abc.Add(-1, 1, 0);
                else return abc.Add(1, -1, 0);
            }

            if (s1 == "AC")
            {
                if (abc.A == 0) return abc.Add(1, 0, -1);
                else if (abc.C == 0 || s2.Contains("C")) return abc.Add(-1, 0, 1);
                else return abc.Add(1, 0, -1);
            }

            if (abc.B == 0) return abc.Add(0, 1, -1);
            else if (abc.C == 0 || s2.Contains("C")) return abc.Add(0, -1, 1);
            else return abc.Add(0, 1, -1);
        }

        class ABC
        {
            public long A { get; set; }
            public long B { get; set; }
            public long C { get; set; }
            public char Add(long a, long b, long c)
            {
                A += a;
                B += b;
                C += c;
                if (a == 1) return 'A';
                if (b == 1) return 'B';
                return 'C';
            }
        }
    }
}


Measured memory_bytes: 32648
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	static pii a[1000010] = {};
	for (int n; cin >> n&&n;) {
		memset(a, 0, sizeof(a));
		rep(h, 0, n) {
			int c, m, s;
			cin >> c;
			a[h].second = c;
			rep(i, 0, 4) {
				cin >> m >> s;
				a[h].first += m * 60 + s;
			}
		}
		sort(a, a + n);
		cout << a[0].second << endl;
		cout << a[1].second << endl;
		cout << a[n - 2].second << endl;
	}
	return 0;
}

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

int A, B, C, K;

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

  if(K <= A) cout << K << endl;
  else if(K > A && K <= A + B) cout << A << endl;
  else cout << A - (K-A-B) << endl;

  return 0;
}

Measured memory_bytes: 3636
function Main(input) {
  input = input.trim();
  if (input === "Sunny") {
    console.log("Cloudy");
  } else if (input === "Cloudy") {
    console.log("Rainy");
  } else {
    console.log("Sunny");
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>
 
int main()
{
 
  int i, j;
 
  /* 文字列 */
  char moji[100];
 
  /* 文字列の入力 */
  scanf("%s", moji);
 
  /* 文字数をカウント */
  for(i=0; moji[i]!='\0'; ++i);
 
  for(j =1; j <= i; j ++){
	  printf("x");
	 }

 
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String args[]){


try (Scanner sc = new Scanner(System.in)) {
  int w = sc.nextInt();
  int n = sc.nextInt();
  int[] values = new int[w];
  for (int i = 0; i < values.length; i++) { 
    values[i] = i + 1;
  }
  for (int i = 0; i < n; i++) {
  String str = sc.next();
  String[] ab = str.split(",");
  int a = Integer.parseInt(ab[0]) - 1; int b = Integer.parseInt(ab[1]) - 1;
  int tmp = values[a];
  values[a] = values[b];
  values[b] = tmp; // aとbを使ってvaluesを操作しよう
  }
  for(int i=0;i<values.length;i++){
    System.out.println(values[i]);
    }
  
  // valuesを出力しよう
  } 
}
  }


Measured memory_bytes: 26300
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();

		int happy=0;
		for(int i=0; i<N-1; i++) {
			if(S.charAt(i)==S.charAt(i+1)) {
				happy ++;
			}
		}
		int ans = Math.min(happy+2*K, N-1);
		System.out.println(ans);
	}
}

Measured memory_bytes: 24224
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[][] dp;
    boolean A, B, C;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];
        dp = new long[N][3];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for (int i = 1; i < N; i++) {
            dp[i][0] = Math.max(dp[i - 1][2], dp[i - 1][1]) + a[i];
            dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + b[i];
            dp[i][2] = Math.max(dp[i - 1][0], dp[i - 1][1]) + c[i];
        }
        System.out.println(Math.max(dp[N - 1][0], Math.max(dp[N - 1][2], dp[N - 1][1])));
    }
}

Measured memory_bytes: 96704
import java.util.Scanner;

public class Main{
  static int n;
  static int[] a;

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

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  }
}


Measured memory_bytes: 50968
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[55][111][3];

int main(){
	int n,k;
	cin>>n>>k;
	rep(i,55)rep(j,111)rep(k,3)dp[i][j][k]=-longinf;
	ll a[n];
	rep(i,n)cin>>a[i];
	dp[0][0][0]=0;
	rep(i,n)rep(j,100){
		dp[i+1][j+1][0]=max(dp[i+1][j+1][0],dp[i][j][0]+a[i]);
		dp[i+1][j+2][0]=max(dp[i+1][j+2][0],dp[i][j][0]);
		dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][0]);
		dp[i+1][j][2]=max(dp[i+1][j][2],dp[i][j][0]);
		dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][1]);
		dp[i+1][j+1][2]=max(dp[i+1][j+1][2],dp[i][j][1]+a[i]);
		dp[i+1][j+1][2]=max(dp[i+1][j+1][2],dp[i][j][2]+a[i]);
		dp[i+1][j+2][2]=max(dp[i+1][j+2][2],dp[i][j][2]);
	}
	ll ans=0;
	rep(j,k+1)rep(i,3)ans=max(ans,dp[n][j][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BKleeneInversion solver = new BKleeneInversion();
        solver.solve(1, in, out);
        out.close();
    }

    static class BKleeneInversion {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            long k = in.nextLong();
            int[] a = new int[n];
            ModInt fore = new ModInt(0);
            ModInt back = new ModInt(0);
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (a[i] < a[j]) fore = fore.add(1);
                    if (a[i] > a[j]) back = back.add(1);
                }
            }
            ModInt ans1 = fore.add(back).mul(k).mul(k - 1).div(2);
            ModInt ans2 = back.mul(k);
            out.println(ans1.add(ans2).getVal());

        }

    }

    static class ModInt {
        long val;
        int MOD = (int) 1e9 + 7;

        public ModInt(long i) {
            this.val = (i + MOD) % MOD;
        }

        public ModInt add(long l) {
            return new ModInt(this.val + l);
        }

        public ModInt mul(long l) {
            return new ModInt(this.val * l);
        }

        public ModInt div(long l) {
            return this.mul(new ModInt(l).inv().val);
        }

        public ModInt add(ModInt m) {
            return new ModInt(this.val + m.getVal());
        }

        public ModInt inv() {
            return this.pow(MOD - 2);
        }

        public ModInt pow(long l) {
            ModInt res = new ModInt(1);
            ModInt v = new ModInt(this.val);
            while (l > 0) {
                if (l % 2 != 0) {
                    res = res.mul(v.val);
                }
                v = v.mul(v.val);
                l /= 2;
            }
            return res;
        }

        public long getVal() {
            return val;
        }

        public String toString() {
            return Long.toString(val);
        }

    }
}



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


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

    int index = 1;
    if (3 <= s){
        while(1){
        if (s == 4) break;
        index++;
        if (s%2 == 0) s /= 2;
        else s = 3*s + 1;
        }
    }
    else index = 1;


    printf("%d\n", index+3);

    

    return 0;
} 



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

int main(){
  int N, Q; cin >> N >> Q;
  string S; cin >> S;
  vector<pair<int, int>> AC(Q);
  for(int i=0;i<Q;i++){
    cin >> AC.at(i).first >> AC.at(i).second;
    AC.at(i).first--;
    AC.at(i).second--;
  }
  vector<int> L(N);
  vector<int> R(N);
  L.at(0)=0;
  R.at(N-1)=0;
  for(int i=1;i<N;i++){
    if(S.at(i-1)=='A' && S.at(i)=='C'){
      L.at(i)=L.at(i-1)+1;
    }
    else L.at(i)=L.at(i-1);
  }
  for(int i=N-2;i>=0;i--){
    if(S.at(i+1)=='C' && S.at(i)=='A'){
      R.at(i)=R.at(i+1)+1;
    }
    else R.at(i)=R.at(i+1);
  }
  int all=L.at(N-1);
  for(int i=0;i<Q;i++){
    cout << L.at(AC.at(i).second)+R.at(AC.at(i).first)-all << endl;
  }
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n; cin >> n;
  vector<int> p(n); rep(i,n) cin >> p[i];
  vector<int> q(n); rep(i,n) cin >> q[i];
  int fac=1; reps(i,1,n+1) fac *= i;
  int a, b;
  
  vector<int> v(n);
  iota(v.begin(), v.end(), 1);
  int cnt=0;
  do {
    if(v==p) a=cnt;
    if(v==q) b=cnt;
    cnt++;
  }while( next_permutation(v.begin(), v.end()) );
  cout << abs(a-b);
  
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5+5;

int n, m, cur;
int u[N], v[N], ans[N];

struct DSU
{
	int connected;
	int par[N], sz[N];

	void init(int n) 
	{
		for(int i=1;i<=n;i++)
		{
			par[i]=i;
			sz[i]=1;
		}
		connected=n;
	}

	int getPar(int k)
	{
		while(k!=par[k])
		{
			par[k]=par[par[k]];
			k=par[k];
		}
		return k;
	}

	int getSize(int k)
	{
		return sz[getPar(k)];
	}

	void unite(int u, int v)
	{
		int par1=getPar(u), par2=getPar(v);

		if(par1==par2)
			return;

		connected--;

		if(sz[par1]>sz[par2])
			swap(par1, par2);

		cur -= sz[par1] * sz[par2];
		sz[par2]+=sz[par1];
		sz[par1]=0;
		par[par1]=par[par2];
	}
};

DSU dsu;

int32_t main()
{
	IOS;
	cin>>n>>m;
	dsu.init(n);
	cur=n*(n-1)/2;
	for(int i=1;i<=m;i++)
		cin>>u[i]>>v[i];
	for(int i=m;i>=1;i--)
	{
		ans[i] = cur;
		dsu.unite(u[i], v[i]);
	}
	for(int i=1;i<=m;i++)
		cout<<ans[i]<<endl;
	return 0;
}



Measured memory_bytes: 5248
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            if self.root[x] < 0:
                return x
            else:
                self.root[x] = self.find_root(self.root[x])
                return self.root[x]

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    edge = []
    for _ in range(M):
        u, v = map(int, input().split())
        edge.append((u, v))

    e2i = {}
    for i, e in enumerate(edge):
        u, v = e
        e2i[u*(N+1)+v] = i
    adj = [[] for _ in range(N+1)]
    ok = [0] * (N+1)
    ans = [0] * M
    edge.sort(key=lambda e: max(A[e[0]-1], A[e[1]-1]))
    UF = UnionFind(N+1)
    adj = [[] for _ in range(N+1)]
    for u, v in edge:
        if UF.isSameGroup(u, v):
            continue
        UF.unite(u, v)
        adj[u].append(v)
        adj[v].append(u)
        if A[u-1] == A[v-1]:
            ok[u] = 1
            ok[v] = 1
            ans[e2i[u*(N+1)+v]] = A[u-1]
        elif A[u-1] < A[v-1]:
            ok[v] = 1
            ans[e2i[u*(N+1)+v]] = A[v-1]
        else:
            ok[u] = 1
            ans[e2i[u*(N+1)+v]] = A[u-1]
    if sum(ok) != N:
        print(-1)
        exit()
    que = deque()
    que.append(1)
    seen = [0] * (N+1)
    seen[1] = 1
    while que:
        v = que.popleft()
        for u in adj[v]:
            if seen[u] == 0:
                seen[u] = seen[v] * (-1)
                que.append(u)
    bw = ['B' if seen[i] == 1 else 'W' for i in range(1, N+1)]
    print(''.join(bw))
    for a in ans:
        if a == 0:
            print(10**9)
        else:
            print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 123592
indices = Hash.new
 
readlines.each do |l|
    word, page = l.chomp.split
    if indices.has_key?(word)
        indices[word] << page.to_i
    else
        indices[word] = [page.to_i]
    end
end
 
indices.sort.each do |word,pages| 
    puts word
    puts pages.sort.join(' ')
end

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

int main() {
    int N; cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < N; ++j) {
            cin >> A[i][j];
        }
    }

    int ans = 0;

    for (int k = 0; k < N; ++k) {
        int tmp = 0;
        for (int i = 0; i <= k; ++i) {
            tmp += A[0][i];
        }
        for (int j = k; j < N; ++j) {
            tmp += A[1][j];
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define KAISU 15000

int inD;
int c[27] = {0};
int s[366][27] = {0};
int t[366] = {0};
int last[366] = {0};
long long int man = 0;

long long int cal_manzoku(void);
void input_A(void);
void input_t(void);
long long int exec_query(int &d, int &q);
void print_t(void);

int main(){

    srand((unsigned) time(NULL));

    input_A();
    // input_t();
    for(auto i=1; i<=inD; ++i){
        t[i] = rand() % 26 + 1;
    }
    man = cal_manzoku();
    // printf("%lld\n", man);

    for(auto i=0; i<KAISU; ++i){
        int rand_day = rand()%365 + 1;
        int rand_t = rand()%26 + 1;
        int t_pre = t[rand_day];
        long long man_pre = man;

        t[rand_day] = rand_t;
        man = cal_manzoku();
        if(man_pre > man){
            t[rand_day] = t_pre;
        }

    }
    print_t();

    // int m;
    // scanf("%d", &m);
    // for(int i=1; i<=m; ++i){
    //     int d,q;
    //     scanf("%d %d", &d, &q);
    //     man = exec_query(d, q);
    //     print_t();
    //     printf("%lld\n", man);
    // }

}

void print_t(void){
    for(int i=1; i<=inD; ++i){
        printf("%d\n", t[i]);
    }
    // printf("\n");
}

void input_A(){
    scanf("%d", &inD);
    for(int i=1; i<=26; ++i){
        scanf("%d", &c[i]);
    }
    
    // // Test
    // for(int i=1; i<=26; ++i){
    //     printf("%d ", c[i]);
    // }
    // printf("\n\n");

    for(int i=1; i<=inD; ++i){
        for(int j=1; j<=26; ++j){
            scanf("%d", &s[i][j]);
        }
    }
    // // Test
    // for(int i=1; i<=inD; ++i){
    //     for(int j=1; j<=26; ++j){
    //         printf("%d ", s[i][j]);
    //     }
    //     printf("\n");
    // }
    // printf("\n\n");

    return;
}

void input_t(){

    // 問題B入力
    for(int i=1; i<=inD; ++i){
        scanf("%d", &t[i]);
    }

    // // Test
    // for(int i=1; i<=inD; ++i){
    //     printf("%d ", t[i]);
    // }
    // printf("\n\n");
}

long long int cal_manzoku(){

    long long int manzoku=0;

    for(int day=1; day<=inD; ++day){
        long long int down = 0;
        last[t[day]] = day;
        for(int i=1; i<=26; ++i){
            down += c[i]*(day - last[i]);
            // printf("down %d %lld %d %d\n", day, down, c[i], last[i]);
        }

        manzoku = manzoku + s[day][t[day]] - down;
        // printf("manzoku %d %d %lld %d %lld\n", day, t[day], manzoku, s[day][t[day]], down);
        // printf("last %d %d\n", t[day], last[t[day]]);

        // printf("%lld\n", manzoku);
    }

    return(manzoku);

}

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

int main(){
    string S;
    cin >> S;
    int value =700;

    if(S[0]=='o')value += 100;
    if(S[1]=='o')value += 100;
    if(S[2]=='o')value += 100;

    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	int n, i = 0,ans=1,m;
	cin >> n;
	vector <int>a(n),k(1000000,0);
	rep(i, n) {
		cin >> a.at(i);
	}
	m = a.at(0);

	while (1) {
		if (ans>=n) {
			cout << -1 << endl;
			return 0;
		}
		if (m == 2) {
			cout << ans << endl;
			return 0;
		}
		m = a.at(m - 1);
		ans++;
	}	
	return 0;
}



Measured memory_bytes: 7460
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    long a;cin>>a;
    int b;cin>>b;
    long c = pow(100,a);
    if(b == 100){b=101;}
    long k =c*b;
    cout<<k;
    return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
    cin>>N;
  int64_t pre=0;
  int64_t Ans=1;

  vector<int64_t> A(N);
  for(int i=0;i<N;i++){

    cin>>A.at(i);

  }
    sort(A.begin(),A.end());
  int64_t max=(1000000000000000000/A.at(N-1))+1;
  

  
    for(int i=0;i<N;i++){
      if(i<N-1&&Ans>max){
      Ans=-1;
      break;
    }
      if(i>0){
      pre=Ans;
      }
    Ans*=A.at(i);
            if(Ans>1000000000000000000||Ans<pre){
      Ans=-1;
      break;
    }
     if(i!=0&&pre!=0&&(Ans/pre)!=A.at(i)){
       Ans=-1;
      break;
     }


  }
  
  cout<<Ans<<endl;


}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    int n;
    string str;
    cin >> n >> str;
    str += str[0];

    bool flag = false;
    vector<int> a(n+2, -1); //0:s, 1:w
    for(int s=0; s<2; s++){
        for(int t=0; t<2; t++){
            a[0] = s;
            a[1] = t;
            for(int i=2; i<n+2; i++){
                if(a[i-1]==0){
                    if(str[i-1]=='o'){
                        a[i] = a[i-2];
                    }else{
                        a[i] = 1 -a[i-2];
                    }
                }else{
                    if(str[i-1]=='o'){
                        a[i] = 1 -a[i-2];
                    }else{
                        a[i] = a[i-2];
                    }
                }
            }

            if(a[n]==s && a[n+1]==t){
                flag = true;
                s = 10;
                break;
            }
        }
    }

    if(flag){
        string ans = "";
        for(int i=0; i<n; i++){
            if(a[i]==0) ans += "S";
            else ans += "W";
        }
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

const long long int N_MAX = 3010;
long long int dp[N_MAX][N_MAX];

long long int MOD = 1e9+7;

int main(){
  
  // read problem
  long long int N;
  std::string p;
  scanf("%lld", &N);
  std::cin >> p;
  
  // initialize dp_table
  for(long long int i = 0; i <= N; i++){
    dp[i][0] = 0;
  }
  dp[1][1] = 1;
  
  // fill dp table
  for(long long int i = 2; i <= N; i++){
    for(long long int j = 1; j <= i; j++){
      if(p[N-i] == '<'){
        dp[i][j] = dp[i][j-1] + (dp[i-1][j-1] - dp[i-1][0]);
        dp[i][j] = (dp[i][j]+MOD)%MOD;
      }
      else{ // if(p[N-i] == '>')
        dp[i][j] = dp[i][j-1] + (dp[i-1][i-1] - dp[i-1][j-1]);
        dp[i][j] = (dp[i][j]+MOD)%MOD;
      }
    }
  }
  
  /*std::cerr << "The result of dp table:" << std::endl;
  for(long long int i = 0; i <= N; i++){
    for(long long int j = 0; j <= i; j++){
      std::cerr << dp[i][j] << " ";
    }std::cerr << std::endl;
  }*/
  
  /*long long int ans = 0;
  for(long long int i = 1; i <= N; i++){
    ans += dp[N][i];
    ans = (ans+MOD)%MOD;
  }*/
  
  std::cerr << "Answer:" << std::endl;
  std::cout << dp[N][N] << std::endl;
  
  return 0;
}


Measured memory_bytes: 69120
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let N = parseInt(xs[0]);
   let S = xs[1].split(' ').map(v=>parseInt(v,10));
   let max1 = Math.max(...S);
   let min1 = Math.min(...S);
   console.log(max1-min1);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));


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

int main() {
  int n, q;
  cin >> n >> q;

  vector<stack<int>> s(n);
  for (int i = 0; i < q; ++i) {
    int q, t;
    cin >> q >> t;

    if (q == 0) {
      int x;
      cin >> x;
      s[t].push(x);
    }
    if (q == 1) {
      if (!s[t].empty())
        cout << s[t].top() << endl;
    }
    if (q == 2) {
      if (!s[t].empty())
        s[t].pop();
    }
  }
}


Measured memory_bytes: 4388
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,k,i,j, ans=0
    integer(int64):: md = 998244353
    integer(int64), allocatable:: dp(:),dpsum(:),l(:),r(:)

    read*, n,k
    allocate(dp,source=[(merge(1_8,0_8,i==1),i=1,n)])
    allocate(dpsum(0:n),source=[(merge(1_8,0_8,i==1),i=0,n)])
    allocate(l(k),r(k))

    do i=1,k
        read*, l(i),r(i)
    end do

    do i=2,n
        do j=1,k; block; integer(int64):: ll,rr
            ll = i-r(j); rr=i-l(j)
            if (rr < 1) cycle
            ll = max(ll,1_8)
            dp(i)=mod(dp(i)+dpsum(rr)-dpsum(ll-1),md)
        end block; end do
        ! print'(*(i0,1x))', dp(:)
        dpsum(i)=dpsum(i-1)+dp(i)
    end do
    print'(i0)', dp(n)
end program main

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = min(a, b); i >= 1; --i)
        if (a % i == 0 && b % i == 0)
            if (--k == 0)
            {
                cout << i << endl;
                return 0;
            }
}

Measured memory_bytes: 3604
W,H,x,y,r = map(int,input().split())

w1 = x+r
w2 = x-r
h1 = y+r
h2 = y-r

if w1 <= W and h1 <= H and w2 >= 0 and h2 >= 0:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 5596
#include <stdio.h>

#define BLACK 1
#define WHITE 0
#define INF 2000

int A[100][100], color[100];
int d[100], pi[100];
int n;

void prim() {
  int i, u, v, min;

  for (i = 0; i < n; i++) {
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  while (1) {
    min = INF;
    for (i = 0; i < n; i++) {
        if (color[i] != BLACK && d[i] < min) {
          min = d[i];
          u = i;
        }
    }

    if (min == INF) break;
    color[u] = BLACK;
    for (v = 0; v < n; v++) {
      if (A[u][v] == -1) continue;
      if (color[v] != BLACK && A[u][v] < d[v]) {
        d[v] = A[u][v];
      }
    }
  }
}

int main() {
  int i, j, sum = 0;
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      scanf("%d", &A[i][j]);
    }
  }
  prim();
  for (i = 0; i < n; i++) {
    sum += d[i];
  }
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 640
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<i64>();

    let x = calc(n, &mut a);
    println!("{}", x);
}

fn calc(n: usize, a: &mut [i64]) -> f64 {
    a.sort();
    let mut s: i64 = a[0];
    for i in 1..n {
        s += a[i] * pow_of_2(i - 1);
    }
    return s as f64 / pow_of_2(n - 1) as f64;
}


fn pow_of_2(x: usize) -> i64 {
    return 2i64.pow(x as u32);
}


Measured memory_bytes: 4352
odd = input()
even = input()
password = ""
o_index = 0
e_index = 0

while True:
	if not o_index == len(odd):
		password+= odd[o_index]
		o_index+=1

	if not e_index == len(even):
		password+= even[e_index]
		e_index+=1
	
	else:
		break

	
print(password)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    string s;cin>>s;
    int n;cin>>n;
    while(n--){
        string c;
        cin>>c;
        if(c=="print"){
            int a,b;cin>>a>>b;
            cout<<s.substr(a,b-a+1)<<endl;
        }
        else if(c=="reverse"){
            int a,b;cin>>a>>b;
            reverse(s.begin()+a,s.begin()+b+1);
        }
        else{
            int a,b;cin>>a>>b;
            string d;cin>>d;
            for(int j=a;j<=b;j++)s[j]=d[j-a];
        }
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3252
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [a,b,c,d,e]
k = int(input())

com = k + a
count = 0
for i in range(5):
    if(l[i] > com):
        count += 1
if(count > 0):
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
unittest
{
	assert( [ "2 2 3", "1 1 3", "2 1 4", "1 2 5" ].solve == 8 );
	assert( [ "2 5 5", "1 1 3", "2 4 20", "1 2 1", "1 3 4", "1 4 2" ].solve == 29 );
	assert( [ "4 5 10", "2 5 12", "1 5 12", "2 3 15", "1 2 20", "1 1 28", "2 4 26", "3 2 27", "4 5 21", "3 5 10", "1 3 10" ].solve == 142 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto r = 0L;
	auto c = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s %s"( r, c, k );
	auto rcvs = new long[ 3 ][ k ];
	auto ass = new long[][]( r, c );
	foreach( i; 0L .. k )
	{
		input.popFront;
		auto rcv = input.front.split.to!( long[] );
		ass[ rcv[ 0 ] - 1 ][ rcv[ 1 ] - 1 ] = rcv[ 2 ];
	}
	
	// dp[ y行目 ][ x列目 ][ 同じ行で拾ったアイテムの数 ] = 価値の合計
	const Z = 4;
	auto dp = new long[][][]( r, c, Z );
	foreach( y; 0L .. r )
	{
		foreach( x; 0L .. c )
		{
			foreach( z; 0L .. Z )
			{
				// アイテムを拾って移動する場合
				if( z + 1 < Z )
				{
					if( y + 1 < r ) dp[ y + 1 ][ x ][ 0 ] = max( dp[ y + 1 ][ x ][ 0 ], dp[ y ][ x ][ z ] + ass[ y ][ x ] );
					if( x + 1 < c ) dp[ y ][ x + 1 ][ z + 1 ] = max( dp[ y ][ x + 1 ][ z + 1 ], dp[ y ][ x ][ z ] + ass[ y ][ x ] );
				}
				
				// アイテムを拾わずに移動する場合
				if( y + 1 < r ) dp[ y + 1 ][ x ][ 0 ] = max( dp[ y + 1 ][ x ][ 0 ], dp[ y ][ x ][ z ] );
				if( x + 1 < c ) dp[ y ][ x + 1 ][ z ] = max( dp[ y ][ x + 1 ][ z ], dp[ y ][ x ][ z ] );
			}
		}
	}
	
	auto ans = 0L;
	foreach( z; 0L .. Z )
	{
		// アイテムを拾う場合
		if( z + 1 < Z ) ans = max( ans, dp[ $ - 1 ][ $ - 1 ][ z ] + ass[ $ - 1 ][ $ - 1 ] );
		
		// アイテムを拾わない場合
		ans = max( ans, dp[ $ - 1 ][ $ - 1 ][ z ] );
	}
	return ans;
}


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

int main(){
	int d;
	int t;
	int s;
	cin >> d >> t >> s;
	if (((d + (s-1)) / s)==t) cout << "Yes" << endl;
	if (((d + (s-1)) / s)<t) cout << "Yes" << endl;
	if (((d + (s-1)) / s)>t) cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,w[200],c=0,r=0,ans=INF;
  cin >> n;
  rep(i,n)cin >> w[i];
  rep(i,n)c+=w[i];
  rep(i,n){
    rep(j,i+1){
      r+=w[j];
    }
    ans=min(ans,abs(c-2*r));
    r=0;
  }
  printf("%lld",ans);
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 1000100, MAXK = 30;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;



int main()
{
    FAST_IO;

    ll h;
    cin >> h;
    int n;
    ll s= 0;
    cin >> n;
    REP(n) {
        ll a; cin >> a;
         s+=a;
    }

    if (s >= h) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using Mat = vector<vector<int>>;



int main(){
    int n;
    cin >> n;
    vi p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];

    
    vi per(n);
    for(int i=1; i<=n; ++i) per[i-1] = i;

    int a = 0,b = 0;
    int t = 1;
    do{
        ++t;
        bool can_a = true;
        bool can_b = true;
        rep(i,n){
            if(per[i] != p[i]) can_a = false; 
            if(per[i] != q[i]) can_b = false;
        }
        if(can_a) a = t;
        if(can_b) b = t;
    }
    while(next_permutation(all(per)));

    cout(abs(a-b));
    return 0;
}

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

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

	string s;
	cin >> s;
	int curr = 0, mx = 0;
	int i=0;
	while(i<s.length()){
		if(s[i]=='A' or s[i]=='C' or s[i]=='T' or s[i]=='G'){
			curr++;
			mx = max(curr,mx);
		}
		else{
			curr = 0;
		}
		i++;
	}
	cout << mx;
	return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
  int a,b,c;
  int i;
  int count=0;
  scanf("%d%d%d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0) count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
 
  cout << n / 3 << endl;
 
  return 0;
}

Measured memory_bytes: 256