akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<int> solve(string& s, int m) {
        int n = s.length();
        if (s[n - 1] == '1') {
            return {};
        }

        const int INF = 1 << 24;
        vector<int> dp(n + 1, INF);
        vector<int> next(n + 1, n);
        dp[n - 1] = 0;
        deque<int> que;
        que.emplace_back(n - 1);
        for (int i = n - 2; i >= 0; --i) {
            if (s[i] == '1') {
                continue;
            }
            assert(que.size() <= 2);

            while (!que.empty()) {
                int u = que.front();
                if (u > i + m) {
                    que.pop_front();
                } else {
                    break;
                }
            }
            if (que.empty()) {
                break;
            }
            dp[i] = dp[que.front()] + 1;
            next[i] = que.front();
            while (!que.empty()) {
                if (dp[que.back()] == dp[i]) {
                    que.pop_back();
                } else {
                    break;
                }
            }
            que.push_back(i);
        }   

        if (dp[0] >= INF) {
            return {};
        }
        int x = 0;
        vector<int> res;
        while (x < n - 1) {
            int nx = next[x];
            res.push_back(nx - x);
            x = nx;
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;

    Solution sol;
    auto res = sol.solve(s, m);
    if (res.empty()) {
        cout << "-1\n";
    } else {
        int m = res.size();
        for (int i = 0; i < m; ++i) {
            cout << res[i] << (i == m - 1 ? '\n' : ' ');
        }
    }

    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

const ll mod=924844033LL;

const int limit=2000;
ll dp[limit+10][limit+10][4];
ll num[limit+10];

ll dp2[limit+10][limit+10];

ll fact[limit+10];

int main(void){
	int n,k;
	cin >> n >> k;

	dp[0][0][1]=1LL;

	rep(i,limit)rep(j,i+1)rep(mask,4){
		dp[i+1][j][mask>>1]+=dp[i][j][mask];
		dp[i+1][j][mask>>1]%=mod;

		dp[i+1][j+1][(mask>>1)|2]+=dp[i][j][mask];
		dp[i+1][j+1][(mask>>1)|2]%=mod;

		if(mask%2==0){
			dp[i+1][j+1][mask>>1]+=dp[i][j][mask];
			dp[i+1][j+1][mask>>1]%=mod;
		}
	}

	
	dp2[0][0]=1LL;
	int sum=0;

	rep(i,k){
		int idx=(n-i+k-1)/k;
		
		rep(j,idx+1) num[j]=0LL;
		rep(j,idx+1)rep(mask,2) num[j]+=dp[idx][j][mask];

		rep(a,sum+1)rep(b,idx+1){
			dp2[i+1][a+b]+=dp2[i][a]*num[b];
			dp2[i+1][a+b]%=mod;
		}

		sum+=idx;
	}

	fact[0]=1LL;
	rep(i,1,n+1) fact[i]=i*fact[i-1]%mod;

	ll ans=0LL;
	rep(i,n+1){
		if(i&1)
			ans=(ans+(mod-1)*dp2[k][i]%mod*fact[n-i]%mod)%mod;
		else
			ans=(ans+1LL*dp2[k][i]%mod*fact[n-i]%mod)%mod;
	}

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

Measured memory_bytes: 93312
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]


x1, y1, x2, y2 = LI()
res = map(str, [y1-y2+x2, x2-x1+y2, y1-y2+x1, x2-x1+y1])

print(' '.join(res))

Measured memory_bytes: 2940
#include <stdio.h>
int main(){
  int L,A,B,C,D,i;
  scanf("%d %d %d %d %d",&L,&A,&B,&C,&D);
  
  if(A/C>B/D){
    if(A%C==0)L-=A/C;
    else L-=A/C+1;
  }
  else if(A/C<B/D){
    if(B%D==0)L-=B/D;
    else L-=B/D+1;  
  }
  else{
    if(A%C!=0||B%D!=0)L-=(A/C+1);
    else L-=A/C;
  } 
  
  printf("%d\n",L);
  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<string>
#include<vector>
#include<ctime>
#include<stack>
using namespace std;
typedef long long ll;
#define mm(a,b) memset(a,b,sizeof(a))
const int maxn = 1e6 + 50;
int a[maxn], ans[maxn];
int vis[maxn];
int main()
{
	memset(vis, 0, sizeof(vis));
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);

	int mid = n / 2, turn = 1, l = 1, r = n - 1;
	ans[mid] = a[0];
	vis[0] = 1;
	int i = 1, sum = n - 1;
	while (l < r&&sum>1)
	{
		if (turn == 1 && !vis[r] && !vis[r - 1])
		{
			vis[r] = 1;
			vis[r - 1] = 1;
			ans[mid + i] = a[r];
			r--;
			ans[mid - i] = a[r];
			r--;
			sum -= 2;
			i++;
			turn = 0;
		}
		else if (turn == 0 && !vis[l] && !vis[l + 1])
		{
			vis[l] = 1;
			vis[l + 1] = 1;
			ans[mid + i] = a[l];
			l++;
			ans[mid - i] = a[l];
			l++;
			sum -= 2;
			i++;
			turn = 1;
		}
	}
	if (sum == 1)
	{
		if (abs(a[l] - ans[1]) > abs(a[l] - ans[n - 1]))
			ans[0] = a[l];
		else
			ans[n] = a[l];
	}

	if (ans[0] != 0)
	{
		if (abs(ans[0] - ans[1]) < abs(ans[0] - ans[n - 1]))
		{
			ans[n] = ans[0];
			ans[0] = 0;
		}
	}

	//for (int i = 0; i <= n; i++)
		//printf("%d ", ans[i]);
	//printf("\n");

	ll anssum = 0;
	for (int i = 0; i <= n; i++)
	{
		if (ans[i] == 0 || ans[i + 1] == 0) continue;
		anssum += abs(ans[i] - ans[i + 1]);
	}
	printf("%lld\n", anssum);
	return 0;
}

/*
5
10 10 5 5 50
*/

Measured memory_bytes: 10496
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
	x = A[i]
	for j in range(i, -1, -1):
		if j != 0 and A[j - 1] > x:
			A[j] = A[j - 1]
		else:
			A[j] = x
			break
	s = ""
	for j in range(N):
		if j != 0:
			s += " "
		s += str(A[j])
	print(s)



Measured memory_bytes: 5596
import java.util.Scanner;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        double r;
        double f;

        r = sc.nextDouble();



        System.out.printf("%.6f %.6f\n", r*r*Math.PI, 2*r*Math.PI);
    }
}


Measured memory_bytes: 28380
import java.util.*;
public class Main{
    public static void main(String sp[]){
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		ArrayList<Integer> al1 = new ArrayList<>();
		for(int i=0;i<n;i++){
			int temp = sc.nextInt();
			al.add(temp);
			al1.add(temp);
		}
		Collections.sort(al1,Collections.reverseOrder());
		int max = al1.get(0);
		int smax= al1.get(1);
		
		for(int i=0;i<n;i++){
			int val = al.get(i);
			if(val==max){
				System.out.println(smax);
			}else if(val!=max){
				System.out.println(max);
			}
		}
	}
}

Measured memory_bytes: 102428
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ll = readLine()!!.split(" ").map { it.toInt() }.sorted().toIntArray()

    var cnt = 0L
    for (i in 0..n-3) {
        for (j in i+1..n-2) {
            val idx = lowerBound(ll, ll[i]+ll[j], j+1, n-1)
            cnt += idx-(j+1)
        }
    }

    println(cnt)
}

fun lowerBound(list: IntArray, key: Int, start: Int, end: Int): Int {
    var minIdx = start-1
    var maxIdx = end+1

    while (maxIdx - minIdx > 1) {
        val mid = minIdx + (maxIdx - minIdx)/2
        if (list[mid] >= key) {
            maxIdx = mid
        } else {
            minIdx = mid
        }
    }

    return maxIdx
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define MIN(c) (*min_element(ALL(c))) 
#define MAX(c) (*max_element(ALL(c)))
#define ACC(c) (accumulate(ALL(c), 0))
#define SLL(x, n) ((x) << (n))
#define SRL(x, n) ((x) >> (n))
#define MIN2(a, b) ((a) < (b)) ? (a) : (b)
#define MAX2(a, b) ((a) > (b)) ? (a) : (b)
#define MP(a, b) (make_pair((a), (b)))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

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

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    int N, P;
    string S;
    vector<pair<string, int> > res;
    int index[100];
    cin >> N;
    REP(i, N){
        cin >> S;
        cin >> P;
        res.push_back(MP(S, P));
        index[i] = i + 1;
    }
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            if(res[i].first > res[j].first){
                auto tmp = res[j];
                res[j] = res[i];
                res[i] = tmp;
                int t = index[j];
                index[j] = index[i];
                index[i] = t;
            }else if(res[i].first == res[j].first && res[i].second < res[j].second){
                auto tmp = res[j];
                res[j] = res[i];
                res[i] = tmp;
                int t = index[j];
                index[j] = index[i];
                index[i] = t;
            }
        }
    }
    REP(i, N){
        PRINT(index[i]);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  vector<ll> sa(n+1);
  vector<ll> sb(m+1);
  rep1(i,n) sa[i] = sa[i-1]+a[i-1];
  rep1(i,m) sb[i] = sb[i-1]+b[i-1];
  int ans = 0;
  rep(i,n+1){
    if(sa[i] > k) break;
    int ok = 0;
    int ng = m+1;
    while(abs(ok-ng)>1){
      int mid = (ok+ng)/2;
      if(sa[i]+sb[mid] > k) ng = mid;
      else ok = mid;
    }
    ans = max(ans,i+ok);
  }
  cout << ans << endl;
}


Measured memory_bytes: 7932
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


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

    int ans=0;
    for(int i=1;i<=N;i++){
        int c=0;
        for(int j=1;j<=i;j++){
            if(i%j==0) c++;
        }
        if(i%2==1&&c==8) ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

#define T 26

int D;
ll C[30];
ll S[400][30];
ll ANS[400];

void input(){
    cin >> D;
    REP(i,T)
        scanf("%lld", &C[i]);
    REP(i,D)
        REP(j,T)
            scanf("%lld", &S[i][j]);
}

void output(){
    REP(i,D)
        printf("%lld\n", ANS[i]+1);
}

// O(DT) = O(365 * 26) = O(10 ** 4)
void calc_score(ll score[], ll ans[]){
    vector<int> last(T, -1);
    ll s = 0;
    REP(d,D){
        s += S[d][ans[d]];
        last[ans[d]] = d;

        REP(i,T){
            s -= C[i] * (d - last[i]);
        }
        score[d] = s;
    }
}

int main(){
    input();

    ll V[400];
    ll score[400];

    ll sumT = 0;
    REP(i,T)
        sumT += C[i];

    // greedy
    vector<ll> last(T, -1);
    REP(d, D){
        ll high = -1e15;
        ll t;
        ll minus = 0;
        REP(i, T){
            minus += C[i] * (d - last[i]);
        }

        REP(i, T){
            ll m = minus - C[i] * (d - last[i]);
            ll plus = S[d][i];
            ll val = plus - m;
            if(high < val){
                high = val;
                t = i;
            }
        }
        V[d] = t;
        last[t] = d;
    }

    calc_score(score, V);
    //REP(d,D)
    //    cout << score[d] << endl;

    REP(d,D)
        ANS[d] = V[d];
    output();
    return 0;
}


Measured memory_bytes: 3852
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;

int main(void){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
	int n,i,ans=0;
	string a,b,c;
	cin>>n>>a>>b>>c;
	for(i=0;i<n;i++){
		if(a[i]==b[i]&&b[i]==c[i])continue;
		else if(a[i]==b[i]&&b[i]!=c[i]||a[i]==c[i]&&b[i]!=c[i]||c[i]==b[i]&&b[i]!=a[i]){
			ans+=1;
		}
		else ans+=2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

int n,a;
int gcd(int a,int b){
  if(a%b!=0)return gcd(b,a%b);
  else return b;
}

int main(){
  int t;
  std::cin >> n;
  std::cin >> t;
  rep(i,1,n){
    std::cin >> a;
    t = gcd(a,t);
  }
  std::cout << t << '\n';
}


Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
XYH = [lr() for _ in range(N)]
height = [x for x in XYH if x[2] > 0]
zero = [x for x in XYH if x[2] == 0]
answer = None
for x in range(101):
    for y in range(101):
        bl = True
        top = height[0]
        cand = abs(x-top[0]) + abs(y-top[1]) + top[2]
        for x2, y2, h in height[1:]:
            temp = abs(x-x2) + abs(y-y2) + h
            if cand != temp:
                bl = False
                break
        if not bl:
            continue
        for x2, y2, h in zero:
            temp = abs(x-x2) + abs(y-y2) + h
            if temp < cand:
                bl = False
                break
        if bl:
            answer = (x, y, cand)

print(*answer)



Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),a,b,c,d;
		sc.close();
		a=n/1000%10;
		b=n/100%10;
		c=n/10%10;
		d=n%10;
		if(a+b+c+d==7) System.out.print(a+"+"+b+"+"+c+"+"+d+"=7");
		else if(a-b+c+d==7) System.out.print(a+"-"+b+"+"+c+"+"+d+"=7");
		else if(a+b-c+d==7) System.out.print(a+"+"+b+"-"+c+"+"+d+"=7");
		else if(a+b+c-d==7) System.out.print(a+"+"+b+"+"+c+"-"+d+"=7");
		else if(a-b-c+d==7) System.out.print(a+"-"+b+"-"+c+"+"+d+"=7");
		else if(a-b+c-d==7) System.out.print(a+"-"+b+"+"+c+"-"+d+"=7");
		else if(a+b-c-d==7) System.out.print(a+"+"+b+"-"+c+"-"+d+"=7");
		else System.out.print(a+"-"+b+"-"+c+"-"+d+"=7");
	}
}

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

/*
提出前に確認!
- setとmultisetを間違えない
*/

int mod = 1e9 + 7;

long long modpow(long long x, long long y){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1) % mod;
    long long res = modpow(x, y / 2);
    return res * res % mod;
}

int	main(void)
{
	int n;
	cin >> n;
	if (n < 2) cout << 0 << endl;
	else cout << ((2 * mod + modpow(10, n) - 2 * modpow(9, n)) % mod + modpow(8, n)) % mod << endl;
	return (0);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<>());
    int alice=0,bob=0;
    rep(i,n) {
        if (i%2==0) alice+=a[i];
        else bob+=a[i];
    }
    
    cout << alice-bob << endl;

    return 0;   
}

Measured memory_bytes: 3596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int[] n = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
            int K = in.nextInt();
            out.println(n[K - 1]);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
char map[23][23];
int h, w, a, b, x, y;
void f(char ch) {
	if (ch == '^') { a = -1; b = 0; return; }
	if (ch == 'v') { a = 1; b = 0; return; }
	if (ch == '<') { a = 0; b = -1; return; }
	if (ch == '>') { a = 0; b = 1; return; }
}
void f1() {
	if (x + a < 1 || h < x + a || y + b < 1 || w < y + b)return;
	if (map[x + a][y + b] == '.') {
		swap(map[x + a][y + b], map[x][y]);
		x += a; y += b;
	}
	return;
}
void solve() {
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> map[i][j];
			if (map[i][j] == '^' || map[i][j] == 'v' || map[i][j] == '<' || map[i][j] == '>') {
				f(map[i][j]); x = i; y = j;
			}
		}
	}
	string s; cin >> s >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'S') {
			int x1 = x, y1 = y;
			for (; !(x1 + a < 1 || h < x1 + a || y1 + b < 1 || w < y1 + b);) {
				if (map[x1 + a][y1 + b] == '#')break;
				else if (map[x1 + a][y1 + b] == '*') { map[x1 + a][y1 + b] = '.'; break; }
				else {
					x1 += a; y1 += b;
				}
			}
		}
		else {
			if (s[i] == 'U') map[x][y] = '^';
			else if (s[i] == 'D') map[x][y] = 'v';
			else if (s[i] == 'L') map[x][y] = '<';
			else if (s[i] == 'R') map[x][y] = '>';
			f(map[x][y]); f1();
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout << map[i][j];
		}
		cout << endl;
	}
	return;
}
signed main() {
	int n; cin >> n; for (int i = 0; i < n; i++) { if (i)cout << endl; solve(); }
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define N 50
#define M 300
using namespace std;
typedef pair<string,int> P;
vector<P> G[N];

string dijkstra(int S,int T){
  string D[M][N];  
  for(int i=0;i<M;i++) for(int j=0;j<N;j++) D[i][j]="{";
  
  priority_queue<P,vector<P>,greater<P> > Q;
  Q.push(P("",S));
  D[0][S] = "";

  while(!Q.empty()){
    P t = Q.top();Q.pop();
    string cost = t.first;
    int len = cost.size();
    int pos = t.second;
    
    if(len>M-10) return "NO";
    if(pos==T) return cost; 
    if(D[len][pos]<cost) continue;
    
    for(int i=0;i<(int)G[pos].size();i++){
      int npos = G[pos][i].second;
      string ncost = cost+G[pos][i].first;
      int nlen = ncost.size();
      if(D[nlen][npos]<=ncost)continue;
      Q.push(P(ncost,npos));
      D[nlen][npos] = ncost;
    }
  }
  return "NO";
}

int main(){
  int cnt=0;
  while(1){
    cnt++;
    int n,m,s,g;
    cin>>n>>m>>s>>g;
    if(!n&&!m&&!s&&!g) return 0;
    
    for(int i=0;i<N;i++) G[i].clear();

    int D[N][N]={};
    for(int i=0,a,b;i<m;i++){
      string c;
      cin>>a>>b>>c;
      G[a].push_back(P(c,b));
      D[a][b] = 1;
    }

    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  D[i][j] |=D[i][k]+D[k][j]==2;
  
    for(int i=0;i<n;i++)if(!D[i][g]) G[i].clear();

    cout<<dijkstra(s,g)<<endl;
  }
  return 0;
}

Measured memory_bytes: 9252
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



long long gcd(long long a, long long b){
	if (b == 0)return a;
	return gcd(b, a%b);
}


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

	int n;
	long long a=1;

	cin>>n;
	rep(i,n){
		long long t;
		cin>>t;

		a = a / gcd(a,t) * t;
	}

	cout<<a<<endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n+1];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    }
  }
}


Measured memory_bytes: 50968
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int mex=10000000;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 

int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b||a==c||b==c)
   {
       if(a==b&&b==c) cout<<"No"<<endl;
       else cout<<"Yes"<<endl;
   }
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll n, m, a[N], c[N];

bool tmam(int mid){
    ll cnt = 0;
    for(int i = 1; i <= n; i++){
        int idx = lower_bound(a + 1, a + n + 1, mid - a[i]) - a;
        cnt += n + 1 - idx;
        if(cnt >= m) return 1;
    }
    return 0;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
     }
     sort(a + 1, a + n + 1);
     for(int i = 1; i <= n; i++){
        c[i] = c[i - 1] + a[i];
     }
     ll low = 0, high = 2e5, mid, ans;
     while(high >= low){
        mid = (low + high) >> 1;
        if(tmam(mid)){
            ans = mid;
            low = mid + 1;
        }
        else high = mid - 1;
     }
     ans++;
     ll res = 0;
     for(int i = 1; i <= n; i++){
        int idx = lower_bound(a + 1, a + n + 1, ans - a[i]) - a;
        ll cnt = n + 1 - idx;
        res = res + (c[n] - c[idx - 1]) + a[i] * cnt;
        m -= cnt;
     }
     ans--;
     cout << res + ans * m;


    return 0;

}



Measured memory_bytes: 5220
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<bits/stdc++.h>
using namespace __gnu_pbds; 
using namespace std;

#define reset(X) memset(X, 0, sizeof(X))
#define int long long
typedef long long ll;
#define pb push_back
#define se second
#define fi first
#define endl '\n'
#define all(X) X.begin(),X.end()

const int INF=1e9;
const int mod=1e9+7;
const int mod2=998244353;


#define readn(a) int a;cin>>a;
#define readv(a,n) vector<int> a(n);for(int i=0;i<n;i++)cin>>a[i];
#define reada(a,n,m) int a[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++) cin>>a[i][j];


#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define map unordered_map
typedef vector<int> vi;
typedef pair<int, int> pii;
int pow(int a, int b)
{
    int prod=1;
    int mult=a;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod2;
        }
        mult*=mult;
        mult%=mod2;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}
const int MAXN=1e3+10;
int pdp[MAXN][4][2];
int dp(string s, int i, int k, bool is_small)
{    if(k<0)
        return 0;
    if(pdp[i][k][(is_small?1:0)]!=-1)
        return pdp[i][k][(is_small?1:0)];
;
    if(i==s.size())
    {
        if(k==0)
        return 1;
        else
            return 0;
    }
    int mx=s[i]-'0';
    if(is_small)
        mx=9;
    int &ans=pdp[i][k][(is_small?1:0)];
    ans=0;
    for(int j=0;j<=mx;j++)
    {
        if(j!=0)
        ans+=dp(s, i+1, k-1, is_small||(mx!=j));

        else

        ans+=dp(s, i+1, k, is_small||(mx!=j));
    }
    return ans;
}
signed main()
{

  
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE 
    if (fopen("INPUT.txt", "r")) {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        freopen ("OUTPUT_ERROR.txt" , "w" , stderr);
    }
    #endif
//---------------------------------------------------------------------------------------------------
    for(int i=0;i<MAXN;i++)
        for(int j=0;j<4;j++)
            for(int k=0;k<2;k++)
                pdp[i][j][k]=-1;
    int n, k;
    string s;
    cin>>s>>k;
    cout<<dp(s, 0, k, false);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    rep(i,9){
        if(n%(i+1)==0){
            if(n/(i+1)<10){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    


}

/*



 */



Measured memory_bytes: 256
#-------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------

from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[j - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] =  j
    return pi

def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else '0' * (length - len(y)) + y


h, w, m = map(int, input().split())
rs = [0] * h
cs = [0] * w

se = set()
for i in range(m):
    r, c =  map(int, input().split())
    rs[r - 1] += 1
    cs[c - 1] += 1
    se.add((r - 1) * w + c - 1)

rmax = max(rs)
cmax = max(cs)

remax = rs.count(rmax)
cemax = cs.count(cmax)
if remax * cemax > m:
    print(rmax + cmax)
    sys.exit(0)

rmaxs = [i for i, _ in enumerate(rs) if _ == rmax]
cmaxs = [i for i, _ in enumerate(cs) if _ == cmax]
for r in rmaxs:
    for c in cmaxs:
        if r * w + c not in se:
            print(rmax + cmax)
            sys.exit(0)

print(rmax + cmax - 1)


Measured memory_bytes: 137848
import java.util.*;

public class Main {
	 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         for(int i=0; i<7; i++){
        	 int a=sc.nextInt();
        	 int b=sc.nextInt();
        	 System.out.println((a-b));
         }
    }
}

Measured memory_bytes: 17176
#include<bits/stdc++.h>
using namespace std;
int lcs[3030][3030]; // lcs[i][j] lcs from s[0...i-1] to t[0...j-1]
string s,t;

int main(){
	memset(lcs,0,sizeof(lcs));
	cin>>s>>t;
	for(int i=1;i<=s.size();i++){
		for(int j=1;j<=t.size();j++){
			if(s[i-1]==t[j-1])
				lcs[i][j]=1+lcs[i-1][j-1];
			else
				lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);

		}
	}
	int l,r;
	l=s.size(),r=t.size();
	string ret="";
	while(lcs[l][r]>0){
		while(lcs[l-1][r]==lcs[l][r])l--;
		
		while(lcs[l][r-1]==lcs[l][r])r--;

		ret+=t[r-1];
		l--;
		r--;
	}
	reverse(ret.begin(),ret.end());
	cout<<ret<<"\n";

    return 0;
}

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

int main()
{
 long long int L,R;
  cin>>L>>R;
 long long int mini=2018;
  if(R-L>2019)
  {
     cout<<0<<endl;
    return 0;
  }
  for(long long int i=L;i<=R-1;i++)
  {
    for(long long int j=i+1;j<=R;j++)
    {
      //cout<<i<<j<<endl;
        mini=min( (i*j)%2019 , mini );
    }
  }
  cout<<mini<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

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

  string s;
  cin >> s;
  s = string("#") + s + string("#");

  vector<bool> p(s.size(), false);
  rep(i, N) { p[i + 1] = s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.'; }

  bool snuke = true, fnuke = true;
  for (int i = A; i < C; i++) {
    snuke = snuke && (s[i] == '.' || s[i + 1] == '.');
  }
  for (int i = B; i < D; i++) {
    fnuke = fnuke && (s[i] == '.' || s[i + 1] == '.');
  }

  if (C < D) {
    cout << (snuke && fnuke ? "Yes" : "No") << endl;
  } else {
    bool w = false;
    for (int i = B; i <= D; i++) {
      w = w || p[i];
    }
    cout << (snuke && fnuke && w ? "Yes" : "No") << endl;
  }

  return 0;
}

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

using namespace std;

long long attacks(int N, int K, vector<int>& H) {
	sort(H.rbegin(), H.rend());
	return (K < N) ? accumulate(H.begin() + K, H.end(), 0LL) : 0;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> H(N);
	for (int i = 0; i < N; i++)
		cin >> H[i];
	cout << attacks(N, K, H);
	return 0;
}

Measured memory_bytes: 1024
<?php
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($a,$b,$c,$d) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

for($i=0;$i<$N;$i++) {
  list($x,$y) = array_map('intval',explode(" ",trim(fgets(STDIN))));
  $c = new StdClass();
  $c->x = $x;
  $c->y = $y;
  $c->idx = $i;
  $d[]=$c;
  $s[$i]=$x;
}
array_multisort($s,SORT_ASC,$d);

$uft = new UF($N);
$dm=array();
foreach($d as $v) {
  $miny = $v->y;
  while(count($dm)) {
    $l = count($dm)-1;
    if ($dm[$l]->miny>$v->y) break;
    $uft->unite($dm[$l]->idx,$v->idx);
    $miny = min($dm[$l]->miny,$miny);
    array_pop($dm);
  }
  $c = new StdClass();
  $c->miny = $miny;
  $c->idx  = $v->idx;
  $dm[]=$c;

}
for ($i=0;$i<$N;$i++) {
  printf("%d\n",$uft->size($i));
}

//https://atcoder.jp/contests/acl1/submissions/16913401
class UF {
  private $pnode;
  private $sz;
  public function __construct($n)
  {
    $this->pnode = range(0,$n);
    $this->sz = array_fill(0,$n,1);
  }
  public function find($x) {
    return $x==$this->pnode[$x]?$x:$this->pnode[$x]=$this->find($this->pnode[$x]);
  }
  public function unite($x,$y) {
    $x = $this->find($x);
    $y = $this->find($y);
    if ($x==$y) return;
    $this->sz[$x]+=$this->sz[$y];
    $this->pnode[$y]=$x;
  }
  public function same($x,$y) {
    return $this->find($x) == $this->find($y);
  }
  public function size($x) {
    return $this->sz[$this->find($x)];
  }
}


Measured memory_bytes: 166380
import java.util.*;

public class Main {

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

        int n = sc.nextInt();
        int[] lineOne = new int[n];
        int[] lineTwo = new int[n];

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

        int max = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                if (j <= i) {
                    sum += lineOne[j];
                }
                if (j >= i) {
                    sum += lineTwo[j];
                }
            }
            max = Math.max(max, sum);
        }
        System.out.println(max);
    }

}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

template<typename T, class F, const T & I>
struct SegmentTree {
    const F op;
    int n; vector<T> dat;
    SegmentTree() : op() {}
    SegmentTree(F f) : op(f) {}
    T operator [](int i) const { return dat[n + i]; }
    void build(const vector<T>& v) {
        int n_ = v.size(); init(n_); for (int i = 0; i < n_; ++i) dat[n + i] = v[i];
        for (int i = n - 1; i; --i) dat[i] = op(dat[i * 2], dat[i * 2 + 1]);
    }
    void init(int n_) { n = 1; while (n < n_) n *= 2; dat.assign(n * 2, I); }
    template<class T_ = T, class SA = enable_if_t<is_same<remove_reference_t<T_>, T>::value>>
    void update(int k, T_&& v) { dat[k += n] = v; while (k /= 2) dat[k] = op(dat[k * 2], dat[k * 2 + 1]); }
    T query(int a, int b) {
        T vl = I, vr = I;
        for (int l = a + n, r = b + n; l < r; l /= 2, r /= 2) { if (l & 1) vl = op(vl, dat[l++]); if (r & 1) vr = op(dat[--r], vr); }
        return op(vl, vr);
    }
    template<class C> int find(int a, int b, C&& check) const { return find(a, b, check, 1, 0, n); }
private:
    template<class C> int find(int a, int b, C&& check, int k, int l, int r) const {
        if (!check(dat[k]) || r <= a || b <= l) return -1; else if (k >= n) return k - n;
        int m = (l + r) / 2; int vl = find(a, b, check, k * 2, l, m); if (~vl) return vl;
        else return find(a, b, check, k * 2 + 1, m, r);
    }
};

template<typename T> struct max_of {
    template<typename T_L = T, typename T_R = T>
    constexpr T operator ()(T_L&& lhs, T_R&& rhs) const { return max(lhs, rhs); }
};
extern constexpr int identity = 0;

using ST = SegmentTree<int, max_of<int>, identity>;

int main() {
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;

    ST stl, str;
    vector<int> l(N), r(N);

    stl.build(vector<int>(N));
    rep(i, N) {
        if (S[i] == 'x') continue;
        l[i] = stl.query(0, max(0, i - C)) + 1;
        stl.update(i, l[i]);
    }
    str.build(vector<int>(N));
    for (int i = N - 1; i >= 0; --i) {
        if (S[i] == 'x') continue;
        r[i] = str.query(min(N, i + C + 1), N) + 1;
        str.update(i, r[i]);
    }
    rep(i, N) {
        if (l[i]) l[i] += r[i] - 1;
    }

    int mx = *max_element(all(l));
    if (mx > K) {
        return 0;
    }

    stl.build(l);
    rep(i, N) {
        if (l[i] < K) continue;
        int m = max(stl.query(max(0, i - C), i), stl.query(i + 1, min(N, i + C + 1)));
        if (m < K) write(i + 1);
    }
}

Measured memory_bytes: 8196
#include<cstdio>
#include<iostream>

#define INF 2100000000

using namespace std;

int minix(int a,int b,int c){
	if(b>=a && c>=a){
		return a;
	}
	if(a>=b && c>=b){
		return b;
	}
	if(b>=c && a>=c){
		return c;
	}
}

int main(){
	int n;
	int masu[1002][1002];
	int ura[1002][1002];
	char str[1002];
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(int i=1;i<=n;i++){
			scanf("%s",str);
			for(int j=1;j<=n;j++){
				if(str[j-1]=='.'){
					ura[i][j]=0;
				}else{
					ura[i][j]=1;
				}
			}
		}
		for(int i=0;i<=n;i++){
			masu[i][0]=masu[0][i]=0;
		}
		int maxi=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(ura[i][j]==0){
					masu[i][j]=minix(masu[i-1][j],masu[i][j-1],masu[i-1][j-1])+1;
					maxi=max(masu[i][j],maxi);
				}else{
					masu[i][j]=0;
				}
			}
		}
		
		printf("%d\n",maxi);
	}
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
n = int(input())
d = {}

for x in input().split():
    x = int(x)
    if x not in d:
        d[x] = 0
    d[x] += 1

cnt = 0
dcnt = 0
for k in d.keys():
    if d[k]%2==1:
        cnt += 1
    else:
        dcnt += 1

if dcnt%2==0:
    print(cnt+dcnt)
else:
    print(cnt+dcnt-1)


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

using namespace std;

int main() {
	int N, K;
	std::cin >> N >> K;

	std::string S;
	std::cin >> S;

	S[K - 1] = S[K - 1] - ('A' - 'a');

	std::cout << S << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

const int maxn = 5e3 + 5;

typedef long long LL;

LL offset[maxn];
LL dp[maxn];

int n, m;
int a[maxn], b[maxn][205];

int que[205][maxn], front[205], rear[205];

int main(){
    cin >> n >> m;
    a[1] = 0;
    for(int i = 2;i <= n;i++){
        scanf("%d", &a[i]); 
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            scanf("%d", &b[i][j]);
        }
    }
    for(int i = 1;i <= m;i++){
        b[0][i] = 1e9 + 7;
        front[i] = 1, rear[i] = 1;
        que[i][1] = 0;
    }
    long long ans = -1e18;
    for(int i = 1;i <= n;i++){
        memset(offset, 0, sizeof(offset));
        offset[i - 1] -= a[i];
        offset[0] += a[i];
        for(int j = 1;j <= m;j++){
            while(b[que[j][rear[j]]][j] <= b[i][j]){
                int l = que[j][rear[j]];
                int r = que[j][rear[j] - 1];
                offset[l] -= b[l][j];
                offset[r] += b[l][j];
                rear[j]--;
            }
            int l = i, r = que[j][rear[j]];
            offset[l] += b[i][j];
            offset[r] -= b[i][j];
            que[j][++rear[j]] = i;
        }
        for(int j = i;j >= 0;j--){
            offset[j] += offset[j + 1];
            dp[j] += offset[j];
            if(j > 0){
                ans = max(ans, dp[j]);
            }
            //cout << offset[j] << " ";
        }
        //cout << endl;
    }
    cout << ans << endl;
    return 0;
}


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

//int H,W; //??°?????????????????°

int main(){

	int H,W; //main??¢??°????±?????????°

	while(1){ //??????????????????????????????????????????????????°?????????

		cin >> H >> W;

		if( H == 0 && W == 0 ) break; //H=0??????W=0??§??????

		for( int i=0; H > i; i++){ //??????H???????????????

			for( int j=0; W > j; j++){ //?¨??????????W?????????
				cout << "#";
			}
            
            cout << endl; //??????

		}
		
		cout << endl; //????????????????????????

	}

	return 0;
}

Measured memory_bytes: 3008
# 元の数列を次のように一つずらして順列を作るとMODSUMは大きくなりそう
# これが最大化どうかは証明できん
# A = {1,2,3,…,N}
# P = {2,3,4,…,1}
n = int(input())
print((n**2 - n)//2)

Measured memory_bytes: 9116
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define all(v) v.begin(),v.end()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);
#define curMod 998244353

int main(){
		//do_not_disturb
		int n, i;
		cin >> n;
		string a = "", b = "", s;
		cin >> s;
		if(n&1){
			cout << "No";
			return 0;
		}
		for(i = 0; i < n/2; i++){
			a += s[i];
		}
		for(i = n/2; i < n; i++){
			b += s[i];
		}
		if(a == b){
			cout << "Yes";
		}
		else{
			cout << "No";
		}
		
    return 0;
} // What is to be written here?


Measured memory_bytes: 256
#include<bits/stdc++.h>
//pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>   using orderedSet =tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
#define endl '\n'
//BFS+DFS
#define boundary(i,j) (i>=0 && i<n && j>=0 && j<m)
int X[]={-1,1,0,0};
int Y[]={0,0,1,-1};
int divisors[10000003];
int main()
{
    ll n;
    cin>>n;
    for(ll i=1; i<=n; i++)
        for(ll j=i; j<=n; j+=i)
        ++divisors[j];
    ll ans=0;
    for(ll i=1; i<=n; i++)
        ans+=i*divisors[i];
    cout<<ans<<endl;

}




Measured memory_bytes: 42692
def solve():
    N,A,B = map(int, input().split())
    prod = 1
    MOD = 10**9 + 7
    ans = pow(2,N,MOD) -1 #bit全探索と同じ理屈

    for i in [A,B]:
        num, inv = 1, 1
        for j in range(N-i+1,N+1):
            num = (num * j) % MOD

        for k in range(1, i+1):
            inv = inv * k % MOD
        ans = ans -(num * pow(inv, MOD-2, MOD)) % MOD

    print(ans%MOD)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
using System.IO.Pipes;
using System.Threading;

class Program
{
    static char[] abc = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
    static long mod = 1000000007;
    static long H;
    static long W;
    static long SY;
    static long GY;
    static long SX;
    static long GX;
    static long ans;
    static String[] map;
    static bool[,] used;
    static void Main(string[] args)
    {
        //var S = Console.ReadLine();
        //var N = long.Parse(Console.ReadLine());
        //var N = long.Parse(Console.ReadLine());
        var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        H = HW[0];
        W = HW[1];
        map = new string[H];
        for (int i = 0; i < H; i++)
        {
            map[i] = Console.ReadLine();
        }
        used = new bool[H, W];
        var ans = true;
        var now = 0;
        for (int i = 0; i < H; i++)
        {
            if(map[i][now] != '#')
            {
                ans = false;
                break;
            }
            else
            {
                used[i, now] = true;
            }
            while (now + 1 < W && map[i][now + 1] == '#')
            {
                now++;
                used[i, now] = true;
            }
        }

        for (int i = 0; i < H; i++)
        {
            for (int j   = 0; j < W; j++)
            {
                if (!used[i,j] && map[i][j] == '#')
                {
                    ans = false;
                    break;
                }
            }
        }

        Console.WriteLine(ans ? "Possible": "Impossible");

    }

}

Measured memory_bytes: 28220