akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(void){
	int n,w;
	int input1,input2;
	long long dp[101][100001]={0};
	cin>>n>>w;

	for(int i=0;i<n;i++){
		cin>>input1>>input2;
		for(int j=1;j<=w;j++){
			dp[i+1][j]=max(dp[i][j],j>=input1?dp[i][j-input1]+input2:0);
		}
	}

	cout<<dp[n][w]<<endl;

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    int h[100000];
    for(int i=0;i<N;i++) cin >> h[i];
    ll dp[100000];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        dp[i] = min(dp[i-2] + abs(h[i-2]-h[i]), dp[i-1] + abs(h[i-1]-h[i]));
    }

    cout << dp[N-1] << endl;
    
    return 0;
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
    ifstream in("in.txt");
#else
    istream &in = cin;
#endif
    int x, n;
    in >> x >> n;
    vector<int> p(n);
    vector<char> has(102, 0);
    for (int i = 0; i < n; i++) {
        in >> p[i];
        has[p[i]] = 1;
    }
    int ans = 0;
    for (int i = 1; i <= 101; i++) {
        if (!has[i] && abs(x - i) < abs(x - ans))
            ans = i;
    }
    printf("%d", ans);
	return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;

int main(){

	int a,b,c;

	cin >> a >> b >> c;

	if(a <= b && c <= b){
		puts("Yes");
	}else{
		puts("No");
	}
	

return 0;
}


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

int main(){
  double a,b,c;
  double d , h, ang;
  double PI=acos(-1);

  scanf("%lf%lf%lf",&a,&b,&c);

  ang=c/180*PI;
  
  h = b * sin(ang);

  d = sqrt(pow(a,2) + pow(b,2) - 2 * a * b * cos(ang));

  printf("%f\n", a * h / 2);
  
  printf("%f\n",a + b + d);

  printf("%f\n",h);



  return 0;
}



Measured memory_bytes: 2888
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;

void solve() {

    string ans = "Yes";
    vector<string> a;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string line;
        cin>>line;
        a.pb(line);
    }
    for(int i=1;i<n;i++){
        if(find(a.begin(), a.begin()+i, a[i])<a.begin()+i or a[i].front()!=a[i-1].back()){
            ans = "No";
        }
        
    }
    cout<<ans<<'\n';
    
}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test = 1;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    c = [e for e in lines[0].split(" ")][0]

    return (c, )


def solve(c):

    a = "abcdefghijklmnopqrstuvwxyz"
    i = a.index(c)

    return a[i+1]


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] a = new int[n+1];
        a[0] = 0;
        int[] b = new int[n+1];
        b[0] = 0;
        int[] c = new int[n+1];
        c[0] = 0;


        for(int i = 1; i < n+1; i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();

        }

        int[][] dp = new int[100005][3];
        dp[0][0] = 0;
        dp[0][1] = 0;
        dp[0][2] = 0;
        //dp的三列分别存储在第i天去a，b，c的最大值

        //さっきまでの問題と同じように
        //dp[i]=(i日目までに得られる幸福度の和の最大値)
        //としたいけど、それじゃダメなのだ。例えばa[N]=1,b[N]=1,c[N]=1000だったときには、
        // 最終日にはCを選んだ方が良さそうだけど、前の日にCを選んでたら困るのだ！
        //「2日連続で選べない」という条件は、前の日に何をしたかわかってればどうにかできるから
        //dp[i][j]=(i日目に行動jをして、i日目までに得られる幸福度の和の最大値)
        //を考えれば良さそうなのだ！
        //i日目に行動Aをするには、前日の行動はBかCじゃないとダメだから
        //dp[i][A]=max(dp[i−1][B]+a[i],dp[i−1][C]+a[i])
        //になるのだ！dp[i][B]、dp[i][C]も同様なのだ。
        //最終的な答えは、最終日の行動がどれでもいいから
        //max(dp[N][A],dp[N][B],dp[N][C])
        //なのだ！
        for (int i = 1; i < n+1; i++){
            //当这一天选择为去做A事情的时候，前一天只可能做了b事或者c事情
            //因此只要用a【i】加上前一天的b事情或者c事情就行
            dp[i][0] = Math.max(a[i] + dp[i-1][1], a[i]+dp[i-1][2]);
            dp[i][1] = Math.max(b[i] + dp[i-1][0], b[i] +dp[i-1][2]);
            dp[i][2] = Math.max(c[i] + dp[i-1][0], c[i] +dp[i-1][1]);
        }

        System.out.println(Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2])));
    }

}

Measured memory_bytes: 93724
# -*- coding: utf-8 -*-

'''
5
1 1 2 1 2
'''


N = int(input())
a = list(map(int, input().split()))

import collections

a_0 = a[1:]
first_val = a[0]
# print(a_0)

c = collections.Counter(a_0)
# print(c)

# a_0の同じ数の組み合わせを求める
cnt_0 = 0
for val in c.values():
    cnt_0 += int(val * (val-1) /2)
print(cnt_0)

# 減る分：もともとnだったのはn-1減って、
# 増える分：もともとNだったのはn増える

for i in a_0:
    if i == first_val:
        print(cnt_0)
    else:
        print(cnt_0 + c[first_val] - (c[i]-1))



Measured memory_bytes: 24868
function main()
  
  (H,W) = map(x -> parse(Int,x), split(readline()))
  h = zeros(Int,H)
  w = zeros(Int,W)

  a = ["" for i in 1:H,j in 1:W]
  check = ["." for i in 1:H,j in 1:W]
  
  for i in 1:H
    a[i,:] = split(chomp(readline()),"")
  end
  
  for i in 1:H
    if a[i,:] == check[i,:]
      h[i] += 1
    end
  end
  
  for i in 1:W
    if a[:,i] == check[:,i]
      w[i] += 1
    end
  end
  
  for i in 1:H
    
    if h[i] == 1
      
      continue
      
    else
      
      for j in 1:W
        
        if w[j] == 1
          continue
        else
          print(a[i,j])
        end
        
      end
      
    end
    
    println()
    
  end
  
end

main()

Measured memory_bytes: 121420
#include<stdio.h>
int main(){
  int n;
  int a[100][2];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&a[i][1],&a[i][2]);
  }
  for(int i=0;i<n-2;i++){
    if(a[i][1]==a[i][2] && a[i+1][1]==a[i+1][2] &&  a[i+2][1]==a[i+2][2]){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    lint sum = 0;
    rep(i, n) {
        sum += (s[i] - '0');
    }

    if (sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    string str;cin>>str;
    ll q;cin>>q;
    while(q--){
        ll k;cin>>k;
        ll ans=0,dm=0,d=0,m=0;
        for(ll i=0;i<n;i++){
            if(str[i]=='C')ans+=dm;
            else if(str[i]=='D')d++;
            else if(str[i]=='M')dm+=d,m++;

            if(i<k-1)continue;
            ll pos=i-(k-1);
            if(str[pos]=='D')dm-=m,d--;
            else if(str[pos]=='M')m--;
        }
        cout<<ans<<"\n";
    }
}

Measured memory_bytes: 1948
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
int a=rr,b=rr,T=rr;
 printf("%d",(T/a)*b); 
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  long long answer = 0;
  
  cin >> n;
  
  for(int i = 1; i <= n; i++){
    if((i % 3 > 0) && (i % 5 > 0)){
      answer += i;
    }
  }
  
  
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3672
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Runtime.CompilerServices;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static List<int[]> ReadPairs(int N)
    {
        List<int[]> ans = new List<int[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadInts); }
        return ans;
    }
    static List<long[]> ReadPairsLong(int N)
    {
        List<long[]> ans = new List<long[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadLongs); }
        return ans;
    }
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    void Multi<T>(out T a) => a = cv<T>(ReadStr);
    void Multi<T, U>(out (T,U) ans)
    {
        var ar = ReadStrs;
        ans =(cv<T>(ar[0]), cv<U>(ar[1]));
    }
    void Multi<T, U, V>(out (T,U,V) ans)
    {
        var ar = ReadStrs; 
        ans =(cv<T>(ar[0]), cv<U>(ar[1]),cv<V>(ar[2]));
    }
    void Multi<T,U>(out T a,out U b)
    {
        var ar = ReadStrs; 
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);
    }
    void Multi<T, U, V>(out T a,out U b,out V c)
    {
        var ar = ReadStrs;
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);  c = cv<V>(ar[2]);
    }
    #endregion


    static void Main()
    {
        string s = ReadStr;

        if(s.Length == 1)
        {
            WriteLine("-1 -1");
            return;
        }

        char[] c = new char[3];
        c[0] = s[0];
        c[1] = s[1];
        if(c[0] == c[1])
        {
            WriteLine("1 2");
            return;
        }

        for (int i = 2; i < s.Length; i++)
        {
            c[i % 3] = s[i];

            if(c[0] == c[1] || c[1] == c[2] || c[2] == c[0])
            {
                WriteLine((i-1)+" "+(i+1));
                return;
            }
        }

        WriteLine("-1 -1");
    }



}



Measured memory_bytes: 26328
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
vector<int> G[120];
int V,E;
int visit[120];//0ならまだ辿ってない1なら辿ってる途中２なら既に辿った
bool flag =false;
void dfs_visit(int);
void find_cycle(){
	memset(visit, 0, sizeof(visit));
	for(int i =0;i <V;i++){
		if(!visit[i]){
			dfs_visit(i);
		}
	}
	return;
}
//閉路発見ならtrue
void dfs_visit(int s){
	visit[s]=1;
	for(int i = 0;i <G[s].size();i++){
		if(!visit[G[s][i]]){
			dfs_visit(G[s][i]);
		}else if(visit[G[s][i]]==1){
			flag =true;
			return ;
		}
	}
	visit[s]=2;
	return ;
}


int main(){
	cin>>V>>E;
	for(int i =0;i <E;i++){
		int s,t;
		cin>>s>>t;
		G[s].push_back(t);
	}
	find_cycle();
	cout <<flag<<endl;
	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(u==s)a=a-1;
    if(u==t)b=b-1;
    cout<<a<<" "<<b;
    return 0;


}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#E - Friendships
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int,readline().split())
if K > (N-1)*(N-2)//2:
    print(-1)
else:
    # Nを頂点とするスターグラフを考える
    ans = []
    for i in range(1,N):
        ans.append((i,N))
    M = N*(N-1)//2 - K
    cnt = N-1
    flag = False
    for i in range(1,N):
        for j in range(i+1,N):
            if cnt == M:
                flag = True
                break
            ans.append((i,j))
            cnt += 1
        if flag:
            break
    print(M)
    for x,y in ans:
        print(x,y)

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

public class Program
{
    public static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var dp = new double[nk[0]];
        for (int i = 1; i < dp.Length; i++)
        {
            dp[i] = Math.Pow(2, 1024);
        }
        for (int i = 0; i < nk[0]; i++)
        {
            for (int j = 1; j <= nk[1]; j++)
            {
                if (i + j >= nk[0])
                {
                    continue;
                }
                dp[j + i] = chmin(dp[j + i], dp[i] + Math.Abs(vals[j + i] - vals[i]));
            }
        }
        Console.WriteLine(dp[dp.Length - 1]);
    }

    public static double chmin(double x, double y)
    {
        return x > y ? y : x;
    }
}

Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
int a[10000];
int main()
{
    int n,m,i,j,k,x;
    cin>>i>>j>>k;
    if(abs(i-j)<abs(i-k))
    {
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"B"<<endl;
    }
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = new int[5];
            for (int i = 0; i < 5; i++)
            {
                input[i] = int.Parse(Console.ReadLine());
            }

            var d = input.Select(x => ((x + 9) / 10 * 10) - x).Max();
            var ans = input.Select(x => (x + 9) / 10 * 10).Sum() - d;

            Console.WriteLine(ans);

        }

        
    }
}


Measured memory_bytes: 13268
import math
S = input()
n = len(S)

for i in range(math.ceil(n/2)):
    if S[2*i] != "R" and S[2*i] != "U" and S[2*i] != "D":
        print("No")
        exit()
for i in range(int(n/2)):
    if S[2*i + 1] != "L" and S[2*i + 1] != "U" and S[2*i + 1] != "D":
        print("No")
        exit()
print("Yes")

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

int main() {
  int N, i, n, a;
  cin >> N;
  
  n = N;
  int  sum = 0;
  
  for (int i = 0; i < 8; i++) {
    a = n;
    a %= 10;
    sum += a;
    n /= 10;
   } 
  
  if (N % sum == 0)
    cout << "Yes" << endl;
  
  else
    cout << "No" << endl;
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(string, a, b);

  if (a.length() == b.length()) {
    if (a == b) OUTL("EQUAL");
    else {
      for (int i = 0; i < a.length(); ++i) {
        if (a[i] > b[i]) {
          OUTL("GREATER");
          return 0;
        }
        else if (a[i] < b[i]) {
          OUTL("LESS");
          return 0;
        }
      }
    }
  }

  else if (a.length() > b.length()) {
    OUTL("GREATER");
  }

  else OUTL("LESS");

  return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N = int(input())
A = [None] * N
for i in range(N):
    S, P = input().split()
    A[i] = [S, -int(P), i + 1]

A = sorted(A, key=itemgetter(0, 1))
for s, p, i in A:
    print(i)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long long int s=0;
	for(i=0;i<n-k;i++)
	{
		s+=a[i];
	}
	cout<<s<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
	int i,x,dummy;
	string str,N="North",E="East",W="West",S="South",R="Right",L="Left";
	while(1){
		cin>>x;
		if(x==0){
		break;
		}
		int ans=1;
		int n=5,e=3,w=4,s=2,a=1,b=6;
		for(i=0;i<x;i++){
		cin>>str;
			if(str==N){
				dummy=a;
				a=s;
				s=b;
				b=n;
				n=dummy;
			}
			else if(str==E){
				dummy=a;
				a=w;
				w=b;
				b=e;
				e=dummy;
			}
			else if(str==W){
				dummy=a;
				a=e;
				e=b;
				b=w;
				w=dummy;
			}
			else if(str==S){
				dummy=a;
				a=n;
				n=b;
				b=s;
				s=dummy;
			}
			else if(str==R){
				dummy=n;
				n=w;
				w=s;
				s=e;
				e=dummy;
			}
			else{
				dummy=n;
				n=e;
				e=s;
				s=w;
				w=dummy;
			}
			ans+=a;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import java.io.IOException;
import java.util.Scanner;

public class Main {
	static final int K = 10000;
	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./ALDS1_6_A-in8.txt"));
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		
		int[] c = new int[K + 1];
		for(int i = 0; i < n; ++i) {
			c[Integer.parseInt(sc.next())] += 1;
		}
		sc.close();
		
		StringBuilder sb = new StringBuilder();
		//long start = System.nanoTime();
		for(int i = 0; i <= K; ++i) {
			while(c[i] > 0){
				sb.append(i);
				sb.append(" ");
				c[i] -= 1;
			}
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb);
		//System.out.println((System.nanoTime() - start)/1000/1000 + " ms");
	}

}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> dk(k);
  rep(i, k) {
    int d;
    cin >> d;
    vector<int> ad(d);
    rep(j, d) cin >> ad[j];
    dk[i] = ad;
  }
  set<int> s;
  rep(i, k) {
    vector<int> ad = dk[i];
    rep(j, ad.size()) {
      int v = ad[j];
      s.insert(v);
    }
  }
  int res = n - s.size();
  cout << res << endl;
  return 0;
}


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

using namespace std;

long long n, s;

int main() {
    cin >> n >> s;
    for (int i = 2; 1LL * i * i <= n; ++i) {
        long long val = 0;
        long long x = n;
        while (x > 0) {
            val += x % i;
            x /= i;
        }
        if (val == s) {
            cout << i << endl;
            return 0;
        }
    }
    if (s > n) {
        cout << -1 << endl;
        return 0;
    }
    long long result = 1e18+7;
    for (int i = 1; 1LL * i * i <= n - s; ++i) {
        if ((n - s) % i == 0) {
            long long val;
            {
                val = i + 1;
                if (n / val < val && (val - 1) * (n / val) == n - s && val > 1) {
                    result = min(result, val);
                }
            }
            {
                val = (n - s) / i + 1;
                if (n / val < val && (val - 1) * (n / val) == n - s && val > 1) {
                    result = min(result, val);
                }
            }
        }
    }
    if (result <= n) {
        cout << result << endl;
        return 0;
    }
    if (s == n) {
        cout << n + 1 << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
void solve(){
    ll n,i,a,b;
    vt<ll> ai,bi;
    cin>>n;
    f(i,0,n,1){
        cin>>a>>b;
        ai.pb(a);
        bi.pb(b);
    }
    sort(ai.begin(),ai.end());
    sort(bi.begin(),bi.end());
    if (n&1)
        cout<<(bi[(n-1)/2]-ai[(n-1)/2]+1)<<endl;
    else{
        ld a=(ai[(n-2)/2]+ai[(n/2)])/(ld)2;
        ld b=(bi[(n-2)/2]+bi[(n/2)])/(ld)2;
        cout<<(ll)((b-a)*2+1)<<endl;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 6684
function main()
  
  s = chomp(readline())
  t = chomp(readline())
  n_s = length(s)
  n_t = length(t)
  
  ans = n_t
  for i in 1:n_s-n_t+1
    cnt = 0
    for j in 1:n_t
      if s[i+j-1] != t[j]
        cnt += 1
      end
    end
    ans = min(ans, cnt)
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 158500
#include<stdio.h>

typedef struct{int p,l,r;}Node;
Node T[100000];

int getD(int);
void printC(int,int);

int main(){
  int n,i,k,j,id,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j == 0) T[id].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = id;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p == -1)r = i;
  }

  for(i=0;i<n;i++)printC(i,getD(i));
      
  return 0;
}

int getD(int u){
  int d=0;
  while(T[u].p != -1){
    u = T[u].p;
    d++;
  }
  return d;
}

void printC(int u,int d){
  int i,c;
  c = T[u].l;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",d);

  if(T[u].p == -1)printf("root, ");
  else if(T[u].l == -1)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  i=0;
  while(c != -1){
    if(i)printf(", ");
    printf("%d",c);
    c = T[c].r;
    i++;
  }
  printf("]\n");
}



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

class UnionFind {
public:
  vector<ll> par, siz;
  UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
    for(int i=0; i<sz_; ++i) par[i]=i;
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_,1);
    for(int i=0; i<sz_; ++i) par[i]=i;
  }

  ll root(ll x) {
    while(x!=par[x]) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  void merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x!=y) {
      if(siz[x]<siz[y]) swap(x,y);
      siz[x]+=siz[y];
      par[y]=x;
    }
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  ll N, M; cin>>N>>M;
  vector<pair<ll, ll>> bridges(M);
  vector<ll> ans(M);
  UnionFind islands(N);
  for(int i=0; i<M; ++i) {
    ll x, y; cin>>x>>y; x--; y--;
    bridges[i].first=x; bridges[i].second=y;
  }
  ll inconvenience = N*(N-1)/2;
  for(int i=M-1; i>=0; --i) {
    ll x = bridges[i].first;
    ll y = bridges[i].second;

    ans[i]=inconvenience;

    if(!islands.issame(x,y)) {
      inconvenience+=islands.size(x)*(islands.size(x)-1)/2;
      inconvenience+=islands.size(y)*(islands.size(y)-1)/2;
      islands.merge(x, y);
      inconvenience-=islands.size(x)*(islands.size(x)-1)/2;
    } else {
      islands.merge(x, y);
    }
  }
  for(auto v:ans) cout<<v<<endl;
}


Measured memory_bytes: 7232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(long long i=I;i<A;i+=B)
#define rep(I,A,B) for(long long j=I;j<=A;j+=B)
#define repp(I,A,B) for(long long j=I;j>=A;j-=B)
#define str(A) for(long long k=0;A[k]!='\0';k++)
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
vector <int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
ll arr[100001];
ll dp[100001];
ll n;
ll min(ll a,ll b){
	return a>b?b:a;
}
ll func(ll i)
{
	if(i<0)
		return 1e15;
	if(dp[i]==1e15)
	{
		dp[i]=min(func(i-1)+abs(arr[i]-arr[i-1]),func(i-2)+abs(arr[i]-arr[i-2]));
	}
	return dp[i];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll i;
	cin>>n;
	FOR(0,n,1)
	{
		cin>>arr[i];
	}
	FOR(0,n,1)
	{
		dp[i]=1e15;
	}
	dp[0]=0;
	cout<<func(n-1);
	return 0;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	string s; cin>>s;
	vector<ll> r;
	vector<ll> g;
	vector<ll> b;
	REP(i,n){
		if(s[i]=='R')r.push_back(i);
		if(s[i]=='G')g.push_back(i);
		if(s[i]=='B')b.push_back(i);
	}
	ll ans=r.size()*g.size()*b.size();
	REP(i,r.size()){
		REP(j,g.size()){
			ll tmp;
			tmp=r[i]*2-g[j];
			if(0<=tmp && tmp<n){
				if(s[tmp]=='B'){
					ans--;
					//cout<<r[i]<<" @ "<<g[j]<<endl;
				}
			}
			tmp=g[j]*2-r[i];
			if(0<=tmp && tmp<n){
				if(s[tmp]=='B'){
					ans--;
					//cout<<r[i]<<" / "<<g[j]<<endl;
				}
			}
			if((r[i]+g[j])%2==0){
				tmp=(r[i]+g[j])/2;
				if(s[tmp]=='B'){
					ans--;
					//cout<<r[i]<<" : "<<g[j]<<endl;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
char s[1000];
string e;
int main()
{
	int x=0,n,m=0;;;
	cin>>n>>e;

	for(int i=0 ; i<e.size() ;i++)
	{

			if( e[i] == 'D' )
            {
				x--;

            }
         else
         {
				x++;


         }
			m= max ( x , m ) ;
	}
 cout<<m;
 	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int length;
    char str[1010];
    scanf("%s",str);
    length=strlen(str);

    if(str[length-1]=='s'){
        str[length]='e';
        str[length+1]='s';
        str[length+2]='\0';
    }else{
        str[length]='s';
        str[length+1]='\0';
    }

    printf("%s\n",str);

    return 0;



}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    ins(s);
    map<char,int>T;
    T[s[0]]++;
    T[s[1]]++;
    T[s[2]]++;  
    if(T['A']==3 || T['B']==3) cout << "No" << endl;
    else cout << "Yes" << endl;
   
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N;
    scanf("%d\n", &N);
    int res = 0, resmax = 0, Hp = 0;
    for(int ni=0; ni<N; ni++){
        int H;
        scanf("%d", &H);
        if(Hp < H){
            if(res > resmax){
                resmax = res;
            }
            res = 0;
        } else {
            res++;
        }
        Hp = H;
    }

    if(res > resmax){
        resmax = res;
    }
    printf("%d\n", resmax);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
numbers = list(map(int, input().split()))

def main() :
    x = numbers[n - 1]
    i = 0
    for j in range(n) :
        if numbers[j] <= x :
            numbers[i], numbers[j] = numbers[j], numbers[i]
            i += 1

    [print(numbers[j] if j != i - 1 else '['+str(numbers[j])+']', end = ' ' if j != n - 1 else '\n') for j in range(n)]

if __name__ == '__main__':
    main()



Measured memory_bytes: 16396
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,m = map(int,input().split())

u = Unionfind(n)
count = 0
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    u.union(a,b)

s = set()
for i in range(n):
    s.add(u.find(i))
print(len(s)-1)

Measured memory_bytes: 78960
var
    n:longint;
begin
    readln(n);
    if (n mod 4=0) or (n mod 7=0) then 
        begin 
            writeln('Yes');
            exit;
        end;
    n:=n-7;
    while n>0 do
        begin
            if n mod 4=0 then 
                begin 
                    writeln('Yes');
                    exit;
                end;
            n:=n-7;
        end;
    writeln('No');
end.

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin >> n;
	vector<ll> v(n);
	for(ll i=0; i<n; i++) cin >> v[i];
	ll mx=v[0], ans=0;
	for(ll i=1; i<n; i++){
       if(v[i]<mx) ans+=mx-v[i];
       else mx=max(mx, v[i]);
	}
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define s(x) (x).begin(),(x).end();
using namespace std;
typedef long long ll; 
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; }
const ll INF = 0;

int main(){

    string s,t;
    cin >>s>>t;

    ll dp[3100][3100];

    rep(i,3100)rep(j,3100)dp[i][j] = 0;

    rep(i,s.length()){
        rep(j,t.length()){
            if(s[i]==t[j])dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
    }}

    string ans ="";
    int i = s.size(),j=t.size();
    while(i>0&&j>0){
        if(dp[i][j]==dp[i][j-1])j--;
        else if (dp[i][j]==dp[i-1][j])i--;
        else {
            ans = s[i-1] + ans;
            i--,j--; 
        }
    }

    cout<<ans<<endl;
    
    

}

Measured memory_bytes: 75392
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  string S;
  cin >> S;
  int N = S.size();

  vector<vector<int> > dp(N, vector<int>(2));

  // Init
  {
    int d = S[0] - '0';
    dp[0][0] = d;
    dp[0][1] = 10 - d;
  }

  // Iterate
  for (int i = 1; i < N; ++i) {
    int d = S[i] - '0';
    if (d != 9) {
      dp[i][0] = min(dp[i-1][0] + d, dp[i-1][1] + d + 1);
      dp[i][1] = min(dp[i-1][0] + (10-d), dp[i-1][1] + (10-(d+1)));
    } else {
      dp[i][0] = dp[i-1][0] + d;
      dp[i][1] = min(dp[i-1][0] + (10-d), dp[i-1][1] + (10-(d+1)));
    }
  }

  // Terminate
  int ans = min(dp[N - 1][0], dp[N - 1][1] + 1);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 55940
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7

int main(){
	int N, K;
	char S[90];
	scanf("%d%d", &N, &K);


	scanf("%s", &S);

	if (S[K - 1] == 'A') {
		S[K - 1]= 'a';
	}
	if (S[K - 1] == 'B') {
		S[K - 1] = 'b';
	}
	if (S[K - 1] == 'C') {
		S[K - 1] = 'c';
	}

	printf("%s", S);




}





Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

map<ll,ll> divid(ll x){
    map<ll,ll> mp;
    for(ll a = 2; a * a <= x; a++){
        if(x % a != 0){
            continue;
        }
        ll ex = 0;

        while(x % a == 0){
            ex++;
            x /= a;
        }

        mp[a] += ex;
    }

    //for(auto x:mp) cout << x.first << "^" << x.second << endl;
    if(x != 1) mp[x] += 1;
    return mp;
}

int main(){
    ll n; cin >> n;
    
    map<ll,ll> mp;
    for(ll i = n; i > 0; i--){
        auto ret = divid(i);
        for(auto x : ret){
            mp[x.first] += x.second; 
        }
    }

    ll ans = 1;
    //for(auto x:mp) cout << x.first << "^" << x.second << endl;
    for(auto x:mp){
        ans *= (x.second + 1);
        ans %= ll(1e9+7);
    }
    put(ans);
}

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

int main(){
    ll t,n,k,i,j,ans=0;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)cin>>arr[i];

    for(i=0;i<n;i++)
     for(j=i+1;j<n;j++)
      for(k=j+1;k<n;k++){
        vector<ll> v ={arr[i],arr[j],arr[k]};
        sort(v.begin(),v.end());
        if(v[0]!=v[1] && v[1]!=v[2] && v[0]+v[1]>v[2])ans++;
      }
      
    cout<<ans;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int tans = 0;
  rep(i, s.length()) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C')
      tans++;
    else
      tans = 0;
    ans = max(ans, tans);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const string d = "ABC";
    string s;
    cin >> s;
    ll n = len(s);
    vector<vector<mint>> dp(n + 1, vector<mint>(4, 0));
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, 4) {
            if (s[i] == '?') {
                dp[i + 1][j] = dp[i][j] * 3;
            }
            else {
                dp[i + 1][j] = dp[i][j];
            }
        }
        rep(j, 3) {
            if ((s[i] == d[j]) || (s[i] == '?')) {
                dp[i + 1][j + 1] += dp[i][j];
            }
        }
    }
    cout << dp[n][3].x << endl;
    return 0;
}


Measured memory_bytes: 10300
#if 0
time: 50min
using priority_queue(reverse) to save time.		
#endif
#include <iostream>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;

const int Inf = 10000*100000+100;
int a,b,V,E,R,S,Start[500000+10],To[500000+10],Dis[500000+10],N[500000+10];
int Ans[100000+10];

priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;


int main() {
	cin >> V >> E >> R;
	for (int i=1; i<=E; i++){
		cin >> S >> To[i] >> Dis[i];
		N[i] = Start[S];
		Start[S] = i;
	}
	
	fill(Ans,Ans+100010,Inf);
	Ans[R] = 0;
	Q.push(make_pair(0,R));
	
	while(!Q.empty()){
		a = Q.top().first;
		b = Q.top().second;
		Q.pop();
		if (Ans[b] == a){
			for(int i=Start[b]; i; i=N[i]){
				int t = To[i];
				if (a+Dis[i] < Ans[t]){
					Ans[t] = a+Dis[i];
					Q.push(make_pair(Ans[t],t));
				}
			}
		}	
	}
	
	for (int i=0; i<V; i++){
		if (Ans[i] < Inf){
			cout << Ans[i] << endl;
		}else{
			cout << "INF" << endl;
		}
	}	
}

Measured memory_bytes: 10356
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;


int main() {
  long double a,b,x;
  long double ans;
  cin >> a >> b >> x;

  x /= a; // 奥行きを消す（平面で考える）

  // 半分より多いか少ないかで場合分けをする
  if (x <= a*b/2) { 
    ans = atan2(b, 2*x/b);
  } else {
    ans = atan2(2*(b-x/a), a);
  }


  cout << setprecision(14) << ans * 180.0 / M_PI << endl;
}

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

using namespace std;

vector<int>graph[100005];

int dist[100005],pre[100005];
bool vis[100005];

void bfs(int src){

    queue<int>Q;
    memset(vis,0,sizeof vis);
    Q.push(src);
    vis[src] = 1;
    dist[src] = 0;

    while(!Q.empty()){
        int u = Q.front();
        Q.pop();
        for(int i=0;i<graph[u].size();i++){
            int v = graph[u][i];
            if(vis[v] == 1) continue;
            vis[v] = 1;
            dist[v] = dist[u] + 1;
            pre[v] = u;
            Q.push(v);
        }
    }
}



int main(){
    int n,st,u,v;
    cin >> n >> st;
    for(int i=0; i<st; i++){
        cin >> u>> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    bfs(1);
    cout << "Yes\n";
    for(int i=2; i<=n; i++) cout << pre[i] << '\n';
    return 0;
}


Measured memory_bytes: 10900
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;



int main(){
    LL n;cin >> n;
    vector<vector<int>> a(n,vector<int> (n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n-1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    vector<int> c(n,0);
    vector<int> x(n,0);
    for (int i = 1; i <= n*(n-1)/2+1; i++) {
        bool f = false;
        bool t = false;
        for (int j = 0; j < n; j++) {
            if(x[j]!=i-1) continue;
            if(c[j]==n-1) continue;
            t=true;
            int en = a[j][c[j]];
            if(x[j]==i||x[en]==i) continue;
            if(c[en]==n-1) continue;
            if(j==a[en][c[en]]){
                c[j]++;
                c[en]++;
                x[j]=i;
                x[en]=i;
                f = true;
            }
        }
        if(!t){
            cout << i-1 << endl;
            return 0;
        }
        if(!f){
            puts("-1");
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 4224
N,M=map(int,input().split())
if N==1:
    print(M)
    exit()

if N>=M**0.5:
    for i in range(M//N,0,-1):
        if M%i==0:
            print(i)
            exit()
else:
    for i in range(N,M+1):
        if M%i==0:
            print(M//i)
            exit()
print(1)

Measured memory_bytes: 3060
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IO
import Control.Monad

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  info <- sort . map (\[x,y,z] -> (x,y,z)) <$> getInt2DListBC
  weight <- newArray (1, n) 0 :: IO Arr
  mark <- newArray (1, n) False :: IO Used
  let graph = foldl makeGraphW M.empty info
  ans <- foldM (solve graph weight mark) True [1..n]
  if ans
    then putStrLn "Yes"
    else putStrLn "No"

type Arr = IOUArray Int Int
type Used = IOUArray Int Bool

type EdgeW = (Int, Int, Int)
type Weight = Int
type Vertex = (Int, Weight)
--key:頂点番号, value:隣接点集合
type GraphW = M.IntMap Neighbor
--key:ある点の隣接点の頂点番号, value:辺の重さ
type Neighbor = M.IntMap Weight

solve :: GraphW -> Arr -> Used -> Bool -> Int -> IO Bool
solve graph weight mark ans i = do
  flag <- readArray mark i
  let ne = M.lookup i graph
  if flag || ne == Nothing
    then return ans
    else do
      writeArray mark i True
      ans' <- foldM (dfs graph weight i mark) ans $ M.toList . fromJust $ ne
      return $ ans && ans'

--DFS : 前pre 現在i
dfs :: GraphW -> Arr -> Int -> Used -> Bool -> Vertex -> IO Bool
dfs graph weight pre mark ans (i, w) = do
  isMark <- readArray mark i
  case isMark of
    True -> do
      wi <- readArray weight i
      wp <- readArray weight pre
      return $ ans && wp + w == wi
    False -> do
      writeArray mark i True
      wSum <- readArray weight pre
      writeArray weight i (wSum + w)
      let ne = M.toList . fromJust $ M.lookup i graph
      return =<< foldM (dfs graph weight i mark) ans ne

--重み付き隣接リスト
makeGraphW :: GraphW -> EdgeW -> GraphW
makeGraphW graph (x, y, w) =
  let nX = M.lookup x graph
      nY = M.lookup y graph
      vX = if nX == Nothing
             then M.insert x (addNeighbor (y, w) M.empty) graph
             else M.insert x (addNeighbor (y, w) $ fromJust nX) graph
  in if nY == Nothing
       then M.insert y (addNeighbor (x, negate w) M.empty) vX
       else M.insert y (addNeighbor (x, negate w) $ fromJust nY) vX

addNeighbor :: Vertex -> Neighbor -> Neighbor
addNeighbor (i, weight) ne = M.insert i weight ne

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getInt2DListBC :: IO [[Int]]
getInt2DListBC = map (map bsToInt . BC.words) . BC.lines <$> BC.getContents


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

int fib(int n){
//  return (n == 0 || n == 1) ? 1 : fib(n - 1) + fib(n - 2);
  int memo[1000] = {1, 1};
  for(auto i = 2; i <= n; i++){
    memo[i] = memo[i - 1] + memo[i - 2];
  }
  return memo[n];
}

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

  cout << fib(n) << endl;
   return 0;
}



Measured memory_bytes: 3100