akhauriyash/Code-Regression huggingface dataset:
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    N = int(file())
    print(180 * (N - 2))
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3316
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

Measured memory_bytes: 9208
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		
		int ans = 1;
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int max = h[0];
		for(int i = 1; i < n; i++) {
			if(h[i] >= max && h[i] >= h[i-1]) {
				ans ++;
				max = h[i];
			}
		}
		System.out.println(ans);
		sc.close();
	}
	
}



Measured memory_bytes: 22612
#include <iostream>

using namespace std;
const int mod=1e9 + 7;
int n,m,dp[100002];
bool a[100001];
int main()
{
    //freopen("C.INP","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> m;
    for (int i=1;i<=m;i++)
    {
        int x;
        cin >> x;
        a[x]=1;
    }
    dp[0]=1;
    if (!a[1]) dp[1]=1;
    for (int i=2;i<=n;i++)
    {
        if (a[i])
        {
            continue;
        }
        if (!a[i-1]&&!a[i-2]) dp[i]=(dp[i-1]%mod+dp[i-2]%mod)%mod;
        else if (!a[i-1]) dp[i]=dp[i-1]%mod;
        else if (!a[i-2]) dp[i]=dp[i-2]%mod;
        //cout << "dp[" << i << "] = " << dp[i] << "\n";
    }
    cout << dp[n];
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()
#define M 100000

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i,N) cin >> a[i];

  int cnt[M + 1] = {0};
  REP(i,N) ++cnt[a[i]];

  int res = 0;
  REP(i,M - 1) {
    int tmp = cnt[i] + cnt[i + 1] + cnt[i + 2];
    res = max(res, tmp);
  }
  cout << res << endl;
  return 0;
}



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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=998244353
    N,K=MI()
    
    dp=[0]*N
    dp[0]=1
    
    L=[0]*K
    R=[0]*K
    for i in range(K):
        L[i],R[i]=MI()
    
    
    for i in range(N-1):
        for k in range(K):
            l= i + L[k]
            r= i + R[k] +1
            if l<N:
                dp[l]+=dp[i]
                dp[l]%=mod
            if r<N:
                dp[r]-=dp[i]
                dp[r]%=mod
        if i!=0:
            dp[i+1]+=dp[i]
        dp[i+1]%=mod
        
                
    print(dp[-1])
            
            

main()


Measured memory_bytes: 75416
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	class Pair{
		public long A,B;
		public Pair(long a, long b){
			A = a; B = b;
		}
	}
	public void Solve(){
		
		bool chk = true;
		for(int i=0;i<N;i++){
			chk &= A[i] == B[i];
		}
		if(chk){
			Console.WriteLine(0);
			return;
		}
		
		long cnt = 0;
		long buf = 0;
		for(int i=0;i<N;i++){
			if(A[i] <= B[i]){
				cnt += A[i];
				B[i] -= A[i];
				A[i] = 0;
				buf += B[i];
			}
		}
		
		List<Pair> P = new List<Pair>();
		for(int i=0;i<N;i++){
			if(A[i] != 0){
				P.Add(new Pair(A[i], B[i]));
			}
		}
		
		P.Sort((p, q) => p.B.CompareTo(q.B) * -1);
		foreach(var p in P){
			if(buf > p.A - p.B){
				buf -= p.A - p.B;
				cnt += p.A;
			} else {
				cnt += buf;
			}
		}
		
		Console.WriteLine(cnt);
	}
	
	
	
	
	int N;
	long[] A,B;
	public Sol(){
		N = ri();
		A = new long[N];
		B = new long[N];
		for(int i=0;i<N;i++){
			var d = rla();
			A[i] = d[0]; B[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}



Measured memory_bytes: 17756
function Main(s) {
	s = s.split("\n");
  s[0] = s[0].split(" ").map(a => +a);
  const h = s[0][0];
  const w = s[0][1];
  var ans = "Yes";
  for(var i = 1; i <= h; i++)
  for(var j = 0; j < w; j++){
    if(s[i][j] === ".")continue;
    if(i !== 1) if(s[i-1][j] === "#")continue;
    if(i !== h) if(s[i+1][j] === "#")continue;
    if(j !== 0) if(s[i][j-1] === "#")continue;
    if(j !== w - 1) if(s[i][j+1] === "#")continue;
    ans = "No";
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
/*author:revolIA*/
/*明日を変えるなら今日変えなきゃ*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e4+7;
int Next[maxn][10],Last[10];
int n,ans;
char Str[maxn];
int main(){
    for(int i=0;i<10;i++)Last[i] = -1;
    scanf("%d%s",&n,Str+1);
    for(int i=n;~i;i--){
        memcpy(Next[i],Last,sizeof Last);
        if(i)Last[Str[i]-'0'] = i;
    }
    for(int i=0;i<1000;i++){
        int x = Next[0][i/100];
        if(x == -1)continue;
        int y = Next[x][i/10%10];
        if(y == -1)continue;
        int z = Next[y][i%10];
        if(z == -1)continue;
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORN(i, n, s) for (int i = s; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n) \
  for (int i = 0; i < n; i++) cin >> a[i];
#define PACKN(a, n, s) \
  for (int i = s; i < n; i++) cin >> a[i];
#define LIST(a, n) \
  for (int i = 0; i < n; i++) cout << "[" << i << "] " << a[i] << endl;

using namespace std;

int main() {
  // input
  int N, M;
  IN(N >> M);
  int X[M];
  FOR(i, M) { IN(X[i]); }

  // process
  if (M < N - 1) {
    OUT("0");
    return 0;
  }
  sort(X, X + M);
  int distance[M - 1];
  int distanceSum = 0;
  FOR(i, M - 1) {
    distance[i] = X[i + 1] - X[i];
    distanceSum += distance[i];
  }

  sort(distance, distance + M - 1);

  // 境界面を探す
  int splitSum = 0;
  FOR(i, N - 1) {  // 各境界
    splitSum += distance[M - 2 - i];
  }

  OUT(distanceSum - splitSum);

  return 0;
}

Measured memory_bytes: 1024
A, B, C, X = map(int,open(0).read().split())
cnt = 0 
for a in range(A + 1): 
        for b in range(B + 1): 
                for c in range(C + 1): 
                        if 500 * a + 100 * b + 50 * c == X:
                                cnt += 1
print(cnt)

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	if (n % 10 == 7) {
		cout << "Yes" << endl;

	}
	else if (((n % 100) / 10) == 7) {
		cout << "Yes" << endl;

	}
	else if (((n % 1000) / 100) == 7) {
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;
	}


}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y,d=0,a=0;
cin>>x>>y;
for(int c=0;c<=x;c++)
{
d=x-c;
if(2*c+4*d==y)
{
a=1;
break;
}
}
if(a==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3676
import sys
input=sys.stdin.readline
n=int(input())
ll=[]
for i in range(n):
  a=int(input())
  for _ in range(a):
    x,y=map(int,input().split())
    ll+=[(i,x-1,y)]
c=0
for p in range(2**n):
  if all(p>>i&1<1 or p>>x&1==y for i,x,y in ll):
    c=max(c,sum(p>>i&1 for i in range(n)))
print(c)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int mod=1e9+7;
const int maxn=2e5;
map<ll,ll> f;
ll n;
ll dp(ll n)
{
    if(n==1) return 1;
    if(f.find(n)!=f.end()) return f[n];
    f[n]=2*dp(n/2)+1;
    return f[n];
}
int main()
{
 
    cin>>n;
    cout<<dp(n)<<endl;
    return 0;
}

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

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int a, b, c;
  cin>>a>>b>>c;
  if (a+b >= c-1) {
    cout << b + c << endl;
  } else {
    cout << b + a + b + 1 << endl;
  }
  return 0;
}


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

int w, h, c[51][51];
const int dx[8] = {-1,-1,-1, 0, 0,+1,+1,+1};
const int dy[8] = {-1, 0,+1,-1,+1,-1, 0,+1};


void dfs(int x, int y){
	c[y][x] = 0;
	for(int i = 0; i < 8; i++){
		int mx = x + dx[i], my = y + dy[i];
		if( mx < 0 || my < 0 || w <= mx || h <= my ) continue;
		
		if( c[my][mx] == 1 ) dfs(mx, my);
	}
}

int main(){
	while( cin >> w >> h , w || h ){
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				cin >> c[y][x];
			}
		}
		int ans = 0;
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				if( c[y][x] == 1 ){
					ans++;
					dfs(x, y);
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1236
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args) throws IOException{
		PrintWriter out = new PrintWriter(System.out);
		FastIO sc = new FastIO(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for(int i=360; i<10000000; i+=360) {
			if(i%n==0) {
				ans = i;
				break;
			}
		}
		System.out.println(ans/n);
		out.close();
	}
	static class FastIO {
		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;
		public FastIO(String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}
		public FastIO(InputStream is) throws IOException {
			dis = is;
		}
		int nextInt() throws IOException {
			int ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
		long nextLong() throws IOException {
			long ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
			return (negative) ? -ret : ret;
		}
		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}
		String next() throws IOException {
			StringBuffer ret = new StringBuffer();
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}
 
			return ret.toString();
		}
	}
}

Measured memory_bytes: 32776
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X= sc.nextInt();
		int answer = 1;
		if (X <= 3) {
			System.out.println("1");
		} else {
			for (int i = 2 ; i <= 31; i++) {
				int candidate = i;
				while ( candidate * i <= X) {
					candidate *= i ;
					answer = Math.max(answer, candidate);
			}

		}
			System.out.println(answer);
		}

}
}

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

#pragma warning(disable:4996)
using namespace std;

vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}

int main() {
	int S; cin >> S;
	S *= 4;
	int ans=0;
	for (int h = 1; h <= 1000; ++h) {
		int min_row_sum=h*h/2+1;
		for (int w = 1; w < S / min_row_sum + 2; ++w) {
			if (S % (w*h)==0) {
				int cent_num=S/h/w;

				auto divs(divisor(cent_num));

				for (int y_id = 0; y_id< divs.size(); ++y_id) {
					int x_id=divs.size()-1-y_id;

					const int y=divs[y_id];
					const int x=divs[x_id];

					if(y%2==h%2)continue;
					if(x%2==w%2)continue;

					if(h>y)continue;
					if(w>x)continue;

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


Measured memory_bytes: 3156
import math

n = int(input())

###商及び余りをsとすると、n=m*s+s=s(m+1)、ただし0<s<m
sum_fav = 0
for s in range(1,int(math.sqrt(n))+1):
  if n%s == 0:
    m = n//s-1
    if s < m:
      #print(m)
      sum_fav += m
    else:
      break
  
print(sum_fav)


Measured memory_bytes: 3316
def main():
    n = int(raw_input())
    if n == 2:
        print -1
    elif n == 3 or n == 6:
        ans = [list('.' * n) for _ in xrange(n)]
        c = 0
        for i in xrange(n / 3):
            ans[c][c] = ans[c][c+1] = 'a'
            ans[c+1][c] = ans[c+2][c] = 'b'
            ans[c+2][c+1] = ans[c+2][c+2] = 'c'
            ans[c][c+2] = ans[c+1][c+2] = 'd'
            c += 3
        for l in ans:
            print ''.join(l)
    elif n == 7 or n == 11:
        ans = [list('.' * n) for _ in xrange(n)]
        ans[0][0] = ans[0][1] = 'a'
        ans[0][2] = ans[0][3] = 'b'
        ans[1][0] = ans[1][1] = 'c'
        ans[1][2] = ans[1][3] = 'd'
        ans[0][4] = ans[1][4] = 'e'
        ans[2][1] = ans[2][2] = 'f'
        ans[2][3] = ans[2][4] = 'g'
        ans[2][5] = ans[2][6] = 'h'
        ans[3][4] = ans[4][4] = 'i'
        ans[3][5] = ans[4][5] = 'j'
        ans[3][6] = ans[4][6] = 'k'
        ans[5][0] = ans[6][0] = 'l'
        ans[5][5] = ans[6][5] = 'm'
        ans[5][6] = ans[6][6] = 'n'
        c = 7
        if n == 11:
            ans[c][c] = ans[c][c+1] = 'a'
            ans[c+1][c] = ans[c+1][c+1] = 'b'
            ans[c][c+2] = ans[c+1][c+2] = 'c'
            ans[c][c+3] = ans[c+1][c+3] = 'd'
            ans[c+2][c] = ans[c+3][c] = 'e'
            ans[c+2][c+1] = ans[c+3][c+1] = 'f'
            ans[c+2][c+2] = ans[c+2][c+3] = 'g'
            ans[c+3][c+2] = ans[c+3][c+3] = 'h'
        for l in ans:
            print ''.join(l)
    else:
        s = t = 0
        for i in xrange(1000):
            if (n - 4 * i) % 5 == 0:
                s = i
                t = (n - 4 * i) / 5
                break
        c = 0
        ans = [list('.' * n) for _ in xrange(n)]
        for i in xrange(s):
            ans[c][c] = ans[c][c+1] = 'a'
            ans[c+1][c] = ans[c+1][c+1] = 'b'
            ans[c][c+2] = ans[c+1][c+2] = 'c'
            ans[c][c+3] = ans[c+1][c+3] = 'd'
            ans[c+2][c] = ans[c+3][c] = 'e'
            ans[c+2][c+1] = ans[c+3][c+1] = 'f'
            ans[c+2][c+2] = ans[c+2][c+3] = 'g'
            ans[c+3][c+2] = ans[c+3][c+3] = 'h'
            c += 4
        for i in xrange(t):
            ans[c][c] = ans[c][c+1] = 'a'
            ans[c+1][c] = ans[c+2][c] = 'b'
            ans[c+2][c+1] = ans[c+2][c+2] = 'c'
            ans[c][c+2] = ans[c+1][c+2] = 'd'
            ans[c][c+3] = ans[c][c+4] = 'e'
            ans[c+1][c+3] = ans[c+1][c+4] = 'f'
            ans[c+2][c+3] = ans[c+2][c+4] = 'g'
            ans[c+3][c] = ans[c+4][c] = 'h'
            ans[c+3][c+1] = ans[c+4][c+1] = 'i'
            ans[c+3][c+2] = ans[c+4][c+2] = 'j'
            c += 5
        for l in ans:
            print ''.join(l)
main()


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n; cin >> n;
    ll a[n];
    ll idx[n];
    rep(i,n) {
        cin >> a[i];
        a[i]--;
        idx[a[i]] = i;
    }
    //rep(i,n) {printf("%d ", idx[i]);} printf("\n");
    set<ll> Set;
    for (ll i = -1; i < n+1; i++) Set.insert(i);
    ll ans = 0;
    rep(i,n-1) {
        ll p = idx[i];
        auto itr = Set.lower_bound(p);
        auto itr2 = itr; itr2--;
        auto itr3 = itr; itr3++;
        auto itr1 = itr2;
        auto itr4 = itr3;
        if ((*itr1) != -1) itr1--;
        if ((*itr4) != n) itr4++;
        ll p1 = (*itr1);
        ll p2 = (*itr2);
        ll p3 = (*itr3);
        ll p4 = (*itr4);
        //printf("%d %d %d %d %d\n", p1,p2,p,p3,p4);
        ans += ((p2-p1)*(p3-p)+(p4-p3)*(p-p2))*((ll)i+1);
        //cout << ans << endl;
        Set.erase(p);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9784
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    let [A, B, C] = lines[0].split(' ').map(Number)
    const K = lines[1] - 0

    let c = 0
    while (A >= B) {
        B *= 2
        c++
    }
    while (B >= C) {
        C *= 2
        c++
    }

    console.log(K >= c ? 'Yes' : 'No')

})(input)


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

using namespace std;

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

    ll i,j,n,t=1,k=0,cnt=0,mini=LLONG_MAX,maxi=LLONG_MIN,ans=0;
    ll m;
    string s;
    cin>>s;
    rep(i,0,s.length())
    {
        if(s[i]=='+') cnt++;
        else cnt--;
    }
    ret(cnt)
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{int n;
	cin >> n;
	      if(n>=30){
            cout<<"Yes";
	      }else{
	      cout<<"No";
	      }

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi
#define second se
using namespace std;
typedef pair<int, int> P;

int dy[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx[8] = {1, 0, -1, 1, -1, 1, -1, 0};

signed main(){
    int h, w;
    while(1){
        cin >> h >> w;
        if(h + w == 0) break;
        string s[11];
        rep(i, 0, h) cin >> s[i];
        string ans = "";
        set<string> st;
        rep(i, 0, h){
            rep(j, 0, w){
                rep(k, 0, 8){
                    int y = i;
                    int x = j;
                    string now = "";
                    now += s[i][j];                    
                    for(int l = 1;; l++){
                        y = (y + dy[k] + h) % h;
                        x = (x + dx[k] + w) % w;
                        if(y == i && x == j) break;
                        now += s[y][x];
                        if(!st.count(now)) st.insert(now);
                        else{
                            if(ans.size() == now.size()){
                                if(ans > now) ans = now;
                            }else if(ans.size() < now.size()){
                                ans = now;
                            }
                        }
                    }
                    // cout << i << " " << j << " " << k << " " << now << endl;
                }
            }
        }
        if(ans == "") cout << "0" << endl;
        else cout << ans << endl;
    }
}

Measured memory_bytes: 35728
import sys
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]
def main():
    n = int(input())
    a = [int(input()) for k in range(n)]
    b = [[a[k],k] for k in range(n)]
    b = sorted(b)
    c = [b[k][1] for k in range(n)]
    c = [-1] + c + [100000]
    t = 0
    ans = 0
    for k in range(1,n+1):
        if c[k-1] < c[k]:
            t += 1
        else:
            t = 1
        ans = max(ans,t)
    print(n-ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 90464
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long A, B, M; cin >> A >> B >> M;
	vector<long long>a(A), b(B);
	long long Min_a = 9999999999, Min_b = 9999999999;
	for (int i = 0; i < A; i++) {
		cin >> a.at(i);
		Min_a = min(Min_a, a.at(i));
	}
	for (int i = 0; i < B; i++) {
		cin >> b.at(i);
		Min_b = min(Min_b, b.at(i));
	}
	vector<int>X(M), Y(M), C(M);
	for (int i = 0; i < M; i++) {
		cin >> X.at(i) >> Y.at(i) >> C.at(i);
	}
	long long ans = Min_a + Min_b;
	for (int i = 0; i < M; i++) {
		if (a.at(X.at(i) - 1) + b.at(Y.at(i) - 1) - C.at(i) < ans) ans = a.at(X.at(i) - 1) + b.at(Y.at(i) - 1) - C.at(i);
	}
	cout << ans << endl;
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

// a = max(a, b), a = min(a, b)
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; }





int main(){
  int D, G;
  cin >> D >> G;
  vector<ll> p(D), c(D);
  REP(i, D) cin >> p[i] >> c[i];
  ll ans = INF;
  for(int i = 0; i < (1 << D); i++){
    ll sum = 0;
    ll res = 0;
    for(int j = 0; j < D; j++){
      if(i & (1 << j)){
        sum += 100 * p[j] * (j + 1) + c[j];
        res += p[j];
      }
    }
    if(G <= sum) chmin(ans, res);
    else{
      for(int j = D - 1; j >= 0; j--){
        if(i & (1 << j)) continue;
        for(int k = 0; k < p[j]; k++){
          if (sum >= G) break;
          sum += 100 * (j + 1);
          ++res;
        }
      }
    chmin(ans, res);
    }
  }
print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  long double n, m, d;
  cin >> n >> m >> d;
  long double ans;
  if(d>=1)ans = (m-1)*2.0*(n-d)/(n*n);
  else ans = 1.0/n * (m-1);
  printf("%.10Lf\n",ans);
  return 0;
}

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

int main(){
    int a,b; cin >> a >> b;
    rep(i,1000){
        int ii=i+1;
        if((int)(ii*0.08)==a && (int)(ii*0.1)==b){
            cout << ii << endl;
            break;
        }
        if(ii==1000) cout << -1 << endl;
    }
    /*bool j=true;
    if(25*0.1==b) j=false;
    cout << (int)(25*0.1) << endl;
    */
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

template<typename T>
class CumulativeSum {
	vector<T> a;
	public:
	CumulativeSum(vector<T>& x) : a(x.size() + 1,0) {
		rep(i,x.size()){
			a[i + 1] = a[i] + x[i];
		}
	}
	T get(int l, int r){ // [l, r]の区間の合計を求める
		return a[r + 1] - a[l];
	}
	T operator [] (const int i) const {
		return a[i];
	}
};

template<typename T>
class CumulativeSumXor {
	vector<T> a;
	public:
	CumulativeSumXor(vector<T>& x) : a(x.size() + 1,0) {
		rep(i,x.size()){
			a[i + 1] = a[i] ^ x[i];
		}
	}
	T get(int l, int r){ // [l, r]の区間の合計を求める
		return a[r + 1] ^ a[l];
	}
	T operator [] (const int i) const {
		return a[i];
	}
};

bool C(int l, int r, CumulativeSum<int>& s, CumulativeSumXor<int>& x){
	//cout << l << ' ' << r << ' ' << s.get(l,r) << ' ' << x.get(l,r) << endl;
	return s.get(l,r) == x.get(l,r);
}

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

	vector<int> a(n);
	cin >> a;

	CumulativeSum<int> s(a);
	CumulativeSumXor<int> x(a);

	long long ans = 0;
	rep(i,n){
		//show(i)
		long long right = n, left = i;
		rep(j,30){
			long long mid = (right + left) / 2;
			//cout << left << ' ' << right << endl;
			if(C(i, mid, s, x)) left = mid;
			else right = mid;
		}

		//cout << left << ' ' << i << endl;
		ans += left - i + 1;
	}
	cout << ans << endl;
}


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

int main(int argc, char **argv)
{
	string str; cin >> str;
	char c = str[0];
	bool ok{true};
	for (auto e : str)
	{
		if (e != c)
			ok = false; 
	}
	std::cout << (ok ? "No" : "Yes")<< std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;
 
int main(){
  long long int r,D, x;
  cin >> r >> D >> x;
  
  for (int i = 0; i < 10; i++){
    x = r*x - D;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int n,m;
    char[] s, t;
    scan(n,m);
    s = readln.chomp.to!(char[]);
    t = readln.chomp.to!(char[]);
    s ~= '#';
    t ~= '#';
    s.reverse();
    t.reverse();

    auto dpi = new int[][](n + 1, m + 1);
    auto dpo = new int[][](n + 1, m + 1);

    /+
    foreach (i ; 1 .. n + 1) {
        if (s[i] == 'I') {
            dpi[i][0] = dpo[i-1][0] + 1;
        }
        if (s[i] == 'O') {
            dpo[i][0] = dpi[i-1][0] + 1;
        }
    }

    foreach (j ; 1 .. m + 1) {
        if (t[j] == 'I') {
            dpi[0][j] = dpo[0][j-1] + 1;
        }
        if (t[j] == 'O') {
            dpo[0][j] = dpi[0][j-1] + 1;
        }
    }
    +/

    foreach (i ; 0 .. n + 1) {
        foreach (j ; 0 .. m + 1) {
            if (s[i] == 'I') {
                dpi[i][j] = max(dpi[i][j], dpo[i-1][j] + 1);
            }
            else if(s[i] == 'O') {
                dpo[i][j] = max(dpo[i][j], dpi[i-1][j] + 1);
            }

            if (t[j] == 'I') {
                dpi[i][j] = max(dpi[i][j], dpo[i][j-1] + 1);
            }
            else if (t[j] == 'O') {
                dpo[i][j] = max(dpo[i][j], dpi[i][j-1] + 1);
            }
        }
    }

    debug {
        writefln("%(%(%s %)\n%)", dpi);
        writeln;
        writefln("%(%(%s %)\n%)", dpo);
    }

    int ans;

    foreach (i ; 0 .. n + 1) {
        foreach (j ; 0 .. m + 1) {
            if (dpi[i][j] & 1) {
                ans = max(dpi[i][j], ans);
            }
            else {
                ans = max(dpi[i][j]-1, ans);
            }
        }
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,P=MAP()

print((A*3+P)//2)


Measured memory_bytes: 3064
#include <stdio.h>
int main(){
    int N,i;
    int a[N],b[2];
    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d ",&a[i]);
    }
    int k = 0;
    for(i = 0;i < N;i++){
        if(a[i] != i + 1){
            b[k] = a[i];
            k++;
        }
    }
    if(k > 2)printf("NO\n");
    else printf("YES\n");
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<long long> a(n + 1);
	map<long long, long long> m;
	m[0]++;
	long long ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i + 1];
		a[i + 1] += a[i];
		ans += m[a[i + 1]]++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17064
#include <stdio.h>
int main(void)
{
	int N, M;
	int a[50], b[50];

	scanf("%d %d", &N, &M);
	for(int i=0; i<M; i++)
		scanf("%d %d", &a[i], &b[i]);

	int road[50];
	for(int i=0; i<N; i++)
		road[i]=0;


	for(int i=0; i<M; i++){
		road[a[i]-1] += 1;
		road[b[i]-1] += 1;
	}

	for(int i=0; i<N; i++){
		printf("%d\n",road[i]);
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, m;
  string inp;
  map<string, int> M;
  cin >> n;
  rep(i, n){
    cin >> inp;
    M[inp]++;
  }
  cin >> m;
  rep(i, m){
    cin >> inp;
    M[inp]--;
  }
  int ans=0;
  for(auto p: M){
    if(ans<p.second){
      ans=p.second;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <set>
#include <stack>
#include <stack>
#include <list>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

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

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

int main(){
    
    int n, m, l;
    long long A[105][105] = {{}};
    long long B[105][105] = {{}};
    long long C[105][105] = {{}};
    cin >> n >> m >> l;
    
    rep(i, n){
        rep(j, m){
            cin >> A[i][j];
        }
    }
    
    rep(i, m){
        rep(j, l){
            cin >> B[i][j];
        }
    }
    
    rep(i, n){
        rep(j, m){
            rep(k, l){
            C[i][k] += A[i][j] * B[j][k];
            }
        }
    }
    
    rep(i, n){
        rep(j, l){
            cout << C[i][j];
            if(j != l-1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3352
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		TreeSet<Integer> set = new TreeSet<>();
		int count = 0;  //setの要素数

		for(int i = 0; i < q; i++) {
			int query = sc.nextInt();

			switch(query) {
			case 0:
				int x = sc.nextInt();
				if(set.add(x)) count++;
				System.out.println(count);
				break;

			case 1:
				x = sc.nextInt();
				if(set.contains(x)) System.out.println(1);
				else System.out.println(0);
				break;

			case 2:
				x = sc.nextInt();
				if(set.remove(x)) count--;
				break;

			case 3:
				int l = sc.nextInt();
				int r = sc.nextInt();
				for(int n : set.subSet(l, true, r, true)) {
					System.out.println(n);
				}
				break;
			}
		}
	}

}



Measured memory_bytes: 181740
#![allow(non_snake_case)]

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: i64 = iter.next().unwrap().parse().unwrap();
    println!("{}", (n - 1) / 2);
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define E 2.71828182845905
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define PI 3.14159265
#define mem(x) memset(x,0,sizeof(x));
using namespace std;
  
void sol() {
	int n;
	cin>>n;
	int h[n];
	rep(i,0,n)
	cin>>h[i];
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	rep(i,2,n)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}	
	cout<<dp[n-1]<<endl;
}

int main() {
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
 	//cin>>t;
 	while(t--){	
	sol();
 }

}

Measured memory_bytes: 1408
// H, Wが小さい
// start, goalを全通り試すことを考えた O(HW)
// それ毎にBFSする O(4HW)
//
// 合計で O(4*(HW)**2) = 4.0 x 10 ** 5 だから勝てそう

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const char wall = '#';
vector<vector<char>> fields;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);
//
int H, W;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

ll ans = 0;

void bfs(int sy, int sx, int gy, int gx) {
  P s(sy, sx);
  P g(gy, gx);

  queue<P> que;
  que.push(s);
  vector<vector<bool>> used(20, vector<bool>(20, false));
  vector<vector<ll>> dist(20, vector<ll>(20, 0));
  dist[sy][sx] = 0;
  used[sy][sx] = true;
  while (!que.empty()) {
    P p = que.front(); que.pop();
    //cout << p.first << ", " << p.second << endl;
    for(int i = 0; i < 4; i++) {
      int ny = p.first + dy[i];
      int nx = p.second + dx[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && fields[ny][nx] != wall && !used[ny][nx]) {
        used[ny][nx] = true;
        dist[ny][nx] = dist[p.first][p.second]+1;
        //printf("dist[%d][%d] = %lld\n", ny, nx, dist[ny][nx]);
        if (nx == g.second && ny == g.first) {
          //cout << "x: " << p.first << ", y: "  << p.second << endl;
          ans = max(ans, dist[ny][nx]);
          return;
        }
        que.push(make_pair(ny, nx));
      }
    }
  }
}

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

  cin >> H >> W;
  fields.resize(H);
  rep(i, H) {
    fields[i].resize(W);
    rep(j, W) {
      cin >> fields[i][j];
    }
  }
  map<pair<P, P>, int> mp;

  //bfs(0, 4, 2, 0);
  rep(i, H) {
    rep(j, W) {
      if (fields[i][j] == wall) continue;
      rep(k, H) {
        rep(m, W) {
          if (fields[k][m] == wall) continue;
          P s(i, j);
          P g(k, m);
          if (mp[make_pair(g, s)] != 1) {
            //cout << i << ", " << j << ", "  << k << ", " << m<< endl;
            mp[make_pair(s, g)]++;
            bfs(i, j, k, m);
            //cout << "ans: " << ans << endl;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10240
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right

ll dp[212345][2][3];// dp[till i][choose or not][miss number]

ll inffff = -1123456789123456789;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i, 212345)rep(j, 2)rep(k, 3) dp[i][j][k] = inffff;
    
    
    ll N ;
    cin >> N ;
    vector<ll> nums;
    
    rep(i, N){
        ll inp; cin >> inp;
        nums.pb(inp);
    }

    reverse(all(nums));

    
    ll canmissN = 1;
    if(N % 2 == 1) canmissN = 2;
    
    
    dp[0][0][0] = inffff;
    dp[0][1][0] = nums[0];
    
    dp[0][0][1] = 0;
    dp[0][1][1] = inffff;
    
    dp[0][0][2] = inffff;
    dp[0][1][2] = inffff;
    
    rep(i, N){
        if(i == 0) continue;
        
        rep(j, 3){
            dp[i][0][j] = max(dp[i][0][j], dp[i-1][1][j]);
            if((j-1) >= 0)dp[i][0][j] = max(dp[i][0][j], dp[i-1][0][j-1]);

            
            dp[i][1][j] = dp[i-1][0][j] + nums[i];
        }
    }
    
    ll ans  = inffff;
    
    
    rep(i, 2)rep(j, canmissN + 1){
        ans = max(ans, dp[N-1][i][j]);
    }
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 15284
n = int(input())
r = []
for i in range(n): r.append(int(input()))
start = r[0]
score = r[1] - r[0]
for i in range(1,n):
  if r[i] - start > score: score = r[i] - start
  if r[i] < start: start = r[i]
print(score)

Measured memory_bytes: 15564
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  char c;
  
  cin >> a >> c >> b;
  
  if(c == '+'){
    cout << a + b << endl;
  }else{
    cout << a - b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector> //動的配列
#include<string> 
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <cmath>



typedef long long ll;


using namespace std;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}


int n;
vector<int> vec;

int main(){
    cin>>n;
    int input;
    while (cin>>input){
        vec.push_back(input);
    }
    int memo;
    bool check=false;
    int ans[n+10];
    for (int j=0;j<n;j++){
        for (int i=0;i<vec.size();i++){
            if (vec.at(i)==i+1){
                memo=i;
                check=true;
                ans[j]=i+1;
            }
        }
        if (check==false){
            cout<<-1<<endl;
            return 0;
        }else {
        vec.erase(vec.begin()+memo);
        check=false;
        }
    }
    for (int i=n-1;i>=0;i--){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << "AB";

    cout << "CD"[n >= 1000] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v;

void solve(){
	cin >> n;
	int xr = 0;
	for(int i=0;i<n;i++){
		cin >> x;
		xr^=x;
		v.push_back(x);
	}
	for(int i =0;i<n;i++){
		cout << (xr^v[i])<<" " ;
	}
}

int main(){

	int t= 1;
	while(t--){
		solve();
	}
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int n;
    cin >> n;
    vector<int> v(n), V;
    rep(i, n){
        cin >> v[i];
    }
    sort(all(v), greater<int>());
    v.push_back(0);

    int cnt = 1;
    ll ans = 0;
    rep(i, n){
        if(v[i] == v[i+1]){
            cnt++;
        }else{
            if(cnt >= 4){
                rep(j, 2){
                    V.push_back(v[i]);
                }
            }else if(cnt >= 2){
                rep(j, 1){
                    V.push_back(v[i]);
                }
            }

            cnt = 1;
        }
    }

    if(V.size() == 0){
        cout << 0 << endl;
    }else{
        cout << 1ll * V[0] * V[1] << endl;
    }


    return 0;
}



Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        String a = sc.next();
        if (Character.isUpperCase(a.charAt(0))) {
            out.println('A');
        } else {
            out.println('a');
        }
    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 25464