akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

bool eq(vi P, vi Q) {
	rep(i, P.size()) {
		if (P[i] != Q[i]) {
			return false;
		}
	}
	return true;
}

ll gcd(ll a, ll b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

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

	vi C(N);
	rep(i, N) {
		cin >> C[i];
	}
	sort(all(C), greater<ll>());

	ll ans = 0;

	ll n0 = 1, n1 = 1, n2 = 1;

	repr(i, N) {
		n0 *= 2;
		n0 %= mod;

		if (i == 1) {
			n1 = n0;
		}
		if (i == 2) {
			n2 = n0;
		}
	}

	rep(i, N) {
		ans += (C[i] * (n0 * ((n1 + (i * n2)%mod)%mod)%mod)%mod)%mod;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> A(N);
	FOR(i, 0, N) {
	    cin >> A[i];
	}

	int ans = INT_MAX;
	FOE(mini, A) {

	    vector<int> v;
	    vector<int> tmp;
	    FOR(i, 0, N) {
	        if (A[i] >= mini) {
	            tmp.emplace_back(A[i]);
	        }
	        else {
	            if (tmp.size() >= K) {
                    sort(ALL(tmp));
                    FOR(j, 0, tmp.size() - K + 1) {
                        v.emplace_back(tmp[j]);
                    }
	            }
	            tmp.clear();
	        }
	    }
        if (tmp.size() >= K) {
            sort(ALL(tmp));
            FOR(j, 0, tmp.size() - K + 1) {
                v.emplace_back(tmp[j]);
            }
        }
        if (v.size() >= Q) {
	        sort(ALL(v));
	        ans = min(ans, v[Q - 1] - mini);
	    }
	}

    print(ans);

	return 0;
}

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

struct Point {
	int x,y;
};

bool map[50][50];
const int dx[8] = {1,1,0,-1,-1,-1,0,1};
const int dy[8] = {0,1,1,1,0,-1,-1,-1};
int w,h;

void bfs(int x,int y) {

	queue<Point> q;
	Point p,p2;
	p.x = x;
	p.y = y;

	q.push(p);
	map[p.x][p.y] = false;
	while(!q.empty()) {
		p = q.front();
		q.pop();

		for(int i = 0;i < 8;i++) {
			p2.x = p.x + dx[i];
			p2.y = p.y + dy[i];

			if(p2.x < 0 || p2.x >= w) continue;
			if(p2.y < 0 || p2.y >= h) continue;

			if(map[p2.x][p2.y]) {
				q.push(p2);
				map[p2.x][p2.y] = false;
			}
		}
	}
}

int main() {

	while(cin >> w >> h && !(w == 0 && h == 0)) {
		for(int y = 0;y < h;y++) {
			for(int x = 0;x < w;x++) cin >> map[x][y];
		}
		int ct = 0;
		for(int y = 0;y < h;y++) {
			for(int x = 0;x < w;x++) {
				if(map[x][y]) {
					ct++;
					bfs(x,y);
				}
			}
		}
		cout << ct << endl;
	}

}

Measured memory_bytes: 1216
# UnionFind
class UnionFind():
    def __init__(self, n):
        # uf.parentsで各ノードの親をリストで返す
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        # uf.find(x)で処理を行う
        #　要素xが属するグループの根を返す（経路圧縮）
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        # uf.union(x,y)で処理を行う
        # 要素xが属するグループと要素yが属するグループを併合する
        # 小さい部分木を大きい部分木にくっつける
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        # uf.size(x)で処理を行う
        # 要素xが属するグループの要素数を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):
        # uf.same(x,y)で処理を行う
        # 要素x,yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):
        # uf.members(x)で処理を行う
        # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        # uf.roots()で処理を行う
        #　すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        # uf.group_count()で処理を行う
        # グループの数を返す
        return len(self.roots())

    def all_group_members(self):
        # all_group_members()で処理を行う
        # ｛ルート要素：[グループに属する要素のリスト]｝をdict型で返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        # ルート要素：[グループに属する要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m,k = map(int,input().split())
uf = UnionFind(n)
edge = [0]*(n+1)
anti_edge = [0]*(n+1)
for i in range(m):
    a,b = map(int,input().split())
    edge[a] += 1
    edge[b] += 1
    uf.union(a-1,b-1)
for i in range(k):
    c,d = map(int,input().split())
    if uf.same(c-1,d-1):
        anti_edge[c] += 1
        anti_edge[d] += 1
for i in range(n):
    size = uf.size(i)
    friend = edge[i+1]
    block = anti_edge[i+1]
    print(size-1-friend-block)





Measured memory_bytes: 93784
#include <iostream>
#include <string>
#include <queue>
#include <vector>

using namespace std;

class Graph {
  typedef vector<int> Vector;
  typedef vector<Vector> Matrix;
  typedef queue<int> IntQueue;
  public:
    Graph(int size): size_(size), next_(size) {
    }
    void add_edge(int a, int b) {
      next_[a].push_back(b);
    }
    bool exists_path(int a, int b) {
      vector<bool> has_visited(size_, false);
      IntQueue q;
      q.push(a);
      has_visited[a] = true;
      while (not q.empty()) {
        int x = q.front();
        q.pop();
        for (size_t i = 0; i < next_[x].size(); ++i) {
          int y = next_[x][i];
          if (not has_visited[y]) {
            if (y == b) {
              return true;
            }
            has_visited[y] = true;
            q.push(y);
          }
        }
      }
      return false;
    }
  private:
    int size_;
    Matrix next_;
};

bool solve(int n, string s[]) {
  Graph g(26);
  for (int i = 0; i < n - 1; ++i) {
    size_t pos = 0;
    while (pos < s[i].length() and s[i][pos] == s[i + 1][pos]) {
      ++pos;
    }
    if (pos == s[i].length()) {
      continue;
    } else if (pos == s[i + 1].length()) {
      return false;
    }
    g.add_edge(s[i][pos] - 'a', s[i + 1][pos] - 'a');
    for (int i = 0; i < 26; ++i) {
      for (int j = i + 1; j < 26; ++j) {
        if (g.exists_path(i, j) and g.exists_path(j, i)) {
          return false;
        }
      }
    }
  }
  return true;
}

int main() {
  int n;
  string s[500];
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> s[i];
    }
    if (solve(n, s)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}

Measured memory_bytes: 1264
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#define BOTTOM 0
#define LEFT 1
#define RIGHT 2
#define TOP 3
using namespace std;

class P{
public:
	int x,y;
	P(int xx=0,int yy=0){
		x=xx;
		y=yy;
	}
};

class Segment{
public:
	P p1,p2;
	Segment(P pp1=P(),P pp2=P()){
		p1=pp1;
		p2=pp2;
	}
};

class EndPoint{
public:
	P p;
	int seg,st;
	EndPoint(){}
	EndPoint(P pp,int segg,int stt){
		p=pp;
		seg=segg;
		st=stt;
	}

	bool operator <(const EndPoint &ep)const{
		if(p.y==ep.p.y){
			return st<ep.st;
		}
		return p.y<ep.p.y;
	}
};

EndPoint EP[2000000];

int manhattanIntersection(vector<Segment> S){
	int n=S.size();
	for(int i=0,k=0;i<n;i++){
		if(S[i].p1.y==S[i].p2.y){
			if(S[i].p1.x>S[i].p2.x)swap(S[i].p1,S[i].p2);
		}else if(S[i].p1.y>S[i].p2.y)swap(S[i].p1,S[i].p2);
		if(S[i].p1.y==S[i].p2.y){
			EP[k++]=EndPoint(S[i].p1,i,LEFT);
			EP[k++]=EndPoint(S[i].p2,i,RIGHT);
		}else{
			EP[k++]=EndPoint(S[i].p1,i,BOTTOM);
			EP[k++]=EndPoint(S[i].p2,i,TOP);
		}
	}
	sort(EP,EP+(2*n));
	set<int> BT;
	BT.insert(1000000001);
	int cnt=0;
	for(int i=0;i<2*n;i++){
		if(EP[i].st==TOP){
			BT.erase(EP[i].p.x);
		}else if(EP[i].st==BOTTOM){
			BT.insert(EP[i].p.x);
		}else if(EP[i].st==LEFT){
			set<int>::iterator b=lower_bound(BT.begin(),BT.end(),S[EP[i].seg].p1.x);
			set<int>::iterator e=upper_bound(BT.begin(),BT.end(),S[EP[i].seg].p2.x);
			cnt+=distance(b,e);
		}
	}
	return cnt;
}

int main(void){
	int n;
	vector<Segment> ss;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		Segment s;
		scanf("%d %d",&s.p1.x,&s.p1.y);
		scanf("%d %d",&s.p2.x,&s.p2.y);
		ss.push_back(s);
	}
	printf("%d\n",manhattanIntersection(ss));
	return 0;
}

Measured memory_bytes: 38144
#include<iostream>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
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 double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1e9 + 7;
const string YES = "Yes";
const string NO = "No";

int main() {
    ll x;
    cin >> x;
    ll d = 0;
    int cnt = 0;
    for(int i=1; d<x; ++i){
        d += i;
        cnt ++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(1){
        int n; cin >> n;
        if(n==0)break;
        int ans=-1e9;
        int now=0;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
            ans=max(ans,a[i]);
            if(now+a[i]>=0){
                now+=a[i];
                ans=max(ans,now);
            }else{
                now=max(0,a[i]);
            }
        }
        printf("%d\n",ans);
    }
}



Measured memory_bytes: 3176
def big(a,b):
	if a >= b:
		return a
	else:
		 return b

n = int(input())
a = []
for i in range(2):
	atemp = list(map(int,input().split()))
	a.append(atemp)
table = [[0 for i in range(n+1)] for k in range(2)]
for i in range(n):
	table[0][i+1] = table[0][i] + a[0][i]
for i in range(n):
	table[1][i+1] = big((table[1][i]+a[1][i]),(table[0][i+1]+a[1][i]))
print(table[1][n])

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n;

signed main() {
    cin >> n;
    cout << pow(n,3) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
//#include<ctime>
//#include<cmath>
//#include<queue>

using namespace std;
#define LL long long

inline int read(){
	int x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int INF = 2147483600;
const int MAXN = 200010;

int N; int a[MAXN+1];

inline void No(){
	puts("No"); exit(0);
}
inline void Yes(){
	puts("Yes"); exit(0);
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read();
	for(int i=1;i<=N;i++) a[i]=read();
	sort(a+1,a+N+1);
	if(a[N]-a[1]>1) No();
	if(a[N]==a[1]){
		if(a[N]==N-1) Yes();
		if((N/2)>=a[N]) Yes();
		No();
	} else{
		int cnt=0;
		for(int i=1;i<=N&&a[i]==a[N]-1;i++) cnt++;
		if(cnt==N-1) No();
		if(cnt>a[1]) No();
		if(a[N]-cnt>(N-cnt)/2) No();
		Yes();
	}
	return 0;
}


Measured memory_bytes: 640
N = int(input())
h = list(map(int,input().split()))
inf = float('inf')
dp = [0] + [abs(h[1] - h[0])]+ [inf] * (N - 2)
for i in range(2 , N):
    dp[i] = min(abs(h[i] - h[i - 2]) + dp[i - 2], abs(h[i - 1] - h[i]) + dp[i - 1])
#print(dp)
print(dp[N - 1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  long long int ans = 0;
  for (int i = 1; i < n; i++){
    if (a.at(i-1) > a.at(i)){
      ans = ans + (a.at(i-1)-a.at(i));
      a.at(i) = a.at(i-1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3980
#include <stdio.h>
#include <math.h>
int main(void){
  double r;
  double l,S;
  scanf("%lf\n",&r);
  l = 2 * M_PI * r;
  S = r * r * M_PI;
  printf("%f %f\n",S,l);
  return 0;
}


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

int main()
{
int a,b,i;
cin>>a>>b;
if(a>=1&&a<=9){
    if(b>=1&&b<=9){
        if(a<b){
            for(i=0;i<b;i++){
                cout<<a;
            }
        }
        else if(a>b){
            for(i=0;i<a;i++){
                cout<<b;
            }
        }
        else{
            for(i=0;i<a;i++){
                cout<<a;
            }
        }
    }
}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
 
using namespace std;
 
class Point{
public:
  double x,y;
 
  Point(double x = 0,double y = 0): x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }
  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }
 
};
 
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }
 
const double DINF = 1e20;
int n;
Point ps[2][1010],tmp[1010];
 
inline double getDist(Point p){ return sqrt(p.x*p.x+p.y*p.y); }
 
bool comp_arg(const double &a,const double &b) { return !equals(fabs(a),fabs(b)) && fabs(a) < fabs(b); }
 
void compute(){
  Point grv[2] = {Point(),Point()};
  rep(i,2) rep(j,n) grv[i] = grv[i] + ps[i][j];
  rep(i,2) grv[i] = grv[i] / (double)n;
  rep(i,2) rep(j,n) ps[i][j] = ps[i][j] - grv[i];
  sort(ps[0],ps[0]+n);
 
  vector<double> arg_buf;
  rep(i,min(10,n)) rep(j,n) {
    double dist[2] = { getDist(ps[0][i]), getDist(ps[1][j]) };
    if( !equals(dist[0],dist[1]) ) continue;
    arg_buf.push_back( atan2(ps[0][i].y,ps[0][i].x) - atan2(ps[1][j].y,ps[1][j].x) );
  }
 
  sort(arg_buf.begin(),arg_buf.end(),comp_arg);
  arg_buf.erase(unique(arg_buf.begin(),arg_buf.end()),arg_buf.end());
 
  rep(i,(int)arg_buf.size()){
    double arg = arg_buf[i];
    rep(j,n) tmp[j] = rotate(ps[1][j],arg);
    sort(tmp,tmp+n);
    bool failed = false;
    rep(j,n) if( !( tmp[j] == ps[0][j] ) ) { failed = true; break; }
    if( !failed ) { printf("%.10lf\n",fabs(arg)); break; }
  }
 
}
 
int main(){
  while( cin >> n, n ){
    rep(i,2) rep(j,n) cin >> ps[i][j].x >> ps[i][j].y;
    compute();
  }
  return 0;
}

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

using namespace std;

int main(){

  int m,n_min,n_max;

  while(1){

	cin>>m>>n_min>>n_max;

	if(m==0 && n_min==0 && n_max==0)
	  break;

	vector<int> score(m+1);
	int d=0;
	int num;

	for(int i=1;i<=m;++i)
	  cin>>score[i];

	for(int i=n_min;i<=n_max;++i){
	  if(score[i]-score[i+1] >= d){
		d = score[i]-score[i+1];
		num=i;
	  }
	}
	cout<<num<<endl;
  }
  
}



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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int A;
        cin >> A;
        if (i % 2 == 1 && A % 2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
s=list(input())

for i in range(len(s)//2):
    s=s[:-2]
    key=0
    for i in range(len(s)//2):
        if(s[i]!=s[i+len(s)//2]):
            key=1
    if(key==0):
        print(len(s))
        exit()



Measured memory_bytes: 2940
//#include "Algorithm/LongestIncreasingSubsequence.hpp"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

template <typename T>
int LongestIncreasingSubsequence(const vector<T>& a)
{
    const int n = a.size();
    vector<T> dp(n, INF<T>);
    for (int i = 0; i < n; i++) {
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
        //        *upper_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    return lower_bound(dp.begin(), dp.end(), INF<T>) - dp.begin();
}

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    cout << LongestIncreasingSubsequence(a) << endl;

    return 0;
}

Measured memory_bytes: 4372
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x,int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
		return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
signed main() {
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
	ll
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    cin>>a>>b;
    if(a+b==4){
        cout<<2<<endl;
    }
    else if(a+b==3){
        cout<<3<<endl;
    }
    else{
        cout<<1<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int w,h,n;
    cin>>w>>h>>n;
    // int tot = w*h;
    vector<vector<int> > V(h,vector<int>(w,0));
    for(int i = 0; i < n; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;

        if(c==1)
        {
            for(int i = 0; i < h; i++)
                for(int j = 0; j < a; j++)
                    V[i][j] = 1;
        
            // /tot -= a*h;
        }
        else if(c == 4)
        {
            for(int i = b; i < h; i++)
                for(int j = 0; j < w; j++)
                    V[i][j] = 1;
        }
        else if(c == 2)
        {
            for(int i = 0; i < h; i++)
                for(int j = a; j < w; j++)  V[i][j] = 1;
        }
        else 
        {
           for(int i = 0; i < b; i++)
            for(int j = 0; j < w; j++)
                V[i][j] = 1;
        }
    }
    int tot = 0;
    for(int i = 0; i < h ; i++) for(int j = 0; j < w; j++)  if(V[i][j] == 0)   tot++;
    cout<<tot<<"\n";
    return 0;
}


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

minus = 0
for i in range(n):
    minus += 1 if a[i] < 0 else 0

abs_a = [abs(a[i]) for i in range(n)]

if minus % 2 == 0:
    print(sum(abs_a))
else:
    print(sum(abs_a) - min(abs_a) * 2)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,j,h,w,count=0;	cin>>h>>w;
	bool done[h][w];
	queue<pint> q[2];
	for(i=0;i<h;i++){
		string s;	cin>>s;
		for(j=0;j<w;j++){
			done[i][j]=0;
			if(s[j]=='#'){
				done[i][j]=1;	q[0].push(make_pair(i,j));	count++;
			}
		}
	}
	int timer=0;
	while(count<h*w){
		timer++;
		while(!q[0].empty()){
			pint p = q[0].front();	q[0].pop();
			i=p.first;	j=p.second;
			if(i+1<h && !done[i+1][j]){
				q[1].push((make_pair(i+1,j)));	count++;	done[i+1][j]=1;
			}
			if(i-1>=0 && !done[i-1][j]){
				q[1].push((make_pair(i-1,j)));	count++;	done[i-1][j]=1;
			}
			if(j-1>=0 && !done[i][j-1]){
				q[1].push((make_pair(i,j-1)));	count++;	done[i][j-1]=1;
			}
			if(j+1<w && !done[i][j+1]){
				q[1].push((make_pair(i,j+1)));	count++;	done[i][j+1]=1;
			}
		}
		while(!q[1].empty()){
			q[0].push(q[1].front());	q[1].pop();
		}
	}
	cout<<timer<<endl;
	return 0;
}

Measured memory_bytes: 9488
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		int N = Integer.parseInt(sc.nextLine());
		String[] values = sc.nextLine().split(" ");
		int[] A = Arrays.stream(values).mapToInt(s -> Integer.parseInt(s)).toArray();
		values = sc.nextLine().split(" ");
		int[] B = Arrays.stream(values).mapToInt(s -> Integer.parseInt(s)).toArray();
		long cnt = 0;
		for (int i = 0; i < N; i++) {
			int thisTown = Math.min(A[i], B[i]);
			cnt += thisTown;
			A[i] -= thisTown;
			B[i] -= thisTown;
			int nextTown = Math.min(A[i + 1], B[i]);
			cnt += nextTown;
			A[i + 1] -= nextTown;
			B[i] -= nextTown;
		}
		System.out.println(cnt);
	}
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int Q;
string S;
signed main() {
    deque<char> deq;
    bool reversed = false;
    cin >> S;
    rep(i, S.length()) { deq.push_back(S[i]); }
    cin >> Q;
    rep(i, Q) {
        int T;
        cin >> T;
        if (T == 1) {
            reversed = !reversed;
        }
        if (T == 2) {
            int F;
            char C;
            cin >> F >> C;
            bool f = (F == 1);
            if (f == reversed) { deq.push_back(C); }
            else { deq.push_front(C); }
        }
    }
    if (!reversed) {
        rep(i, deq.size()) { cout << deq[i]; }
    } else {
        for (int i = deq.size() - 1; i >= 0; i--) { cout << deq[i]; }
    }
    cout << endl;
}

Measured memory_bytes: 896
<?php
//Palindrome-philia

$S = trim(fgets(STDIN));
$S_middle_index = strlen($S)/2;

$exchange_count = 0; 
//奇数時
if ( strlen($S)%2 == 1 ) {
    for ( $i=0; $i<strlen($S); $i++ ) {
        if ( $S_middle_index-1 == $i ) {
        break;
        }
        if ( $S[$i] != $S[strlen($S)-1-$i]  ) {
            $S[strlen($S)-1-$i] = $S[$i];
            $exchange_count = $exchange_count + 1;
        }
    }
}
//偶数時
else {
    for ( $j=0; $j<strlen($S); $j++ ) {
        if ( $S_middle_index == $j ) {
            break;
        }
        if ( $S[$j] != $S[strlen($S)-1-$j]  ) {
            $S[strlen($S)-1-$j] = $S[$j];
            $exchange_count = $exchange_count + 1;
        }
    }

}

echo($exchange_count)."\n";

?>

Measured memory_bytes: 16260
A_ = input()
B_ = input()
C_ = input()


next_ = A_[0]
A_ = A_[1::]
while(True):
    if(next_ == 'a'):
        if(A_ == ''):
            print("A")
            break
        next_ = A_[0]
        A_ = A_[1::]
    elif(next_ == 'b'):
        if(B_ == ''):
            print("B")
            break
        next_ = B_[0]
        B_ = B_[1::]
    elif(next_ == 'c'):
        if(C_ == ''):
            print("C")
            break
        next_ = C_[0]
        C_ = C_[1::]
 

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
  int n, d, x, i, j, k;
  scanf("%d%d%d", &n, &d, &x);
  for(i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    x += (d + a - 1) / a;
  }
  printf("%d", x);
  return 0;
}

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


static const int INF = 10000007;

int main()
{
	int h, w;
	int ma[101][101];
	cin >> h >> w;
	string in;
	for (int i = 1; i <= h; ++i)
	{
		cin >> in;
		for (int j = 1; j <= w; ++j)
		{
			ma[i][j] = (in[j-1] == '#');
		}
	}
	int dp[101][101] = {};
	for (int i = 0; i < 101; ++i)
	{
		for (int j = 0; j < 101; ++j)
		{
			dp[i][j] = INF;
		}
	}

	dp[1][0] = dp[0][1] = 0;
	for (int i = 1; i <= h; ++i)
	{
		for (int j = 1; j <= w; ++j)
		{
			dp[i][j] = min((ma[i-1][j]==0&&ma[i][j]?1:0) + dp[i-1][j], (ma[i][j-1]==0&&ma[i][j]?1:0) + dp[i][j-1]);
		}
	}
	cout << dp[h][w] << endl;
	return 0;
}

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

int main() {
    while (1) {
        string s;
        cin >> s;
        if (s == "0")
            return 0;

        long long dp[2][11];
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 11; ++j) {
                dp[i][j] = 0;
            }
        }
        long long ans = 0;
        for (char c : s) {
            int k = c - '0';
            long long nex[2][11];
            for (int i = 0; i < 2; ++i) {
                for (int j = 0; j < 11; ++j) {
                    nex[i][j] = 0;
                }
            }
            ++dp[0][0];
            for (int i = 0; i < 2; ++i) {
                for (int j = 0; j < 11; ++j) {
                    if (k | i) {
                        nex[1][((k - j) % 11 + 11) % 11] += dp[i][j];
                    }
                    else if (i == 1) {
                        nex[i][((k - j) % 11 + 11) % 11] += dp[i][j];
                    }
                }
            }
            for (int i = 0; i < 2; ++i) {
                for (int j = 0; j < 11; ++j) {
                    dp[i][j] = nex[i][j];
                }
            }
            ans += dp[1][0];
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3168
package main

import "fmt"
import "sort"
import "bytes"
	
func main() {
    
	var n, l int
	fmt.Scanf("%d %d",&n, &l)
	
	var s []string
	for i := 0; i < n; i++ {
	    var tmp string
	    fmt.Scanf("%s",&tmp)
	    s = append(s, tmp)
	}
	
	sort.Strings(s)
	
	var buffer bytes.Buffer
	for i := 0; i < n; i++ {
	    buffer.WriteString(s[i])
	}
	
	fmt.Println(buffer.String())
	
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
struct edge {
    int to,id;
    edge(int to, int id) : to(to), id(id) {}
};

vector<vector<edge>> G;
*/
vector<vector<int>> G;
map<pii, int> dic;
vector<vector<int>> pass;
vector<int> root;
void dfs(int id, int v, int to, int pv = -1) {
    if (pv != -1) root.emplace_back(dic[make_pair(pv,v)]);
    if (v == to) {
        for (auto i : root) pass[id].emplace_back(i);
    }
    for (auto nv : G[v]) {
        if (nv == pv) continue;
        dfs(id,nv,to,v);
    }
    if (!root.empty()) root.pop_back();
    return;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    G.resize(N);
    rep(i,N-1) {
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        dic[make_pair(a,b)] = dic[make_pair(b,a)] = i;
    }
    int M; cin >> M;
    vector<pii> uv(M);
    rep(i,M) {
        int u,v; cin >> u >> v;
        u--; v--;
        uv[i] = make_pair(u,v);
    }

    pass.resize(M);
    rep(i,M) {
        int u,v;
        tie(u,v) = uv[i];
        dfs(i,u,v);
    }
    vector<ll> Y(1<<M,1);
    for (int tmp = 0; tmp < (1<<M); tmp++) {
        bitset<20> s(tmp);
        vector<bool> check(N-1);
        rep(i,M) {
            if (s.test(i)) {
                for (auto j : pass[i]) check[j] = true;
            }
        }
        int cnt = 0;
        rep(i,N-1) if (!check[i]) cnt++;
        rep(i,cnt) Y[tmp] *= 2LL;
    }

    ll ans = 0;
    for (int tmp = 0; tmp < (1<<M); tmp++) {
        bitset<20> s(tmp);
        if (s.count()%2==0) ans += Y[tmp];
        else ans -= Y[tmp];
    }

    cout << ans << endl;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
const int N=110;
int n,a[N];
vector <int> ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	bool bl=1;
	for (int i=1;i<=n;i++)
	{
		if (a[i]>i)
		{
			bl=0;
			break;
		}
	}
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	while ((int)ans.size()<n)
	{
		for (int j=n;j>=1;j--)
		{
			if (!a[j]) continue;
			int cnt=0;
			for (int k=1;k<=j;k++) cnt+=(a[k]!=0);
			if (cnt==a[j])
			{
				ans.push_back(a[j]);
				a[j]=0;
				break;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	for (int i=0;i<(int)ans.size();i++) printf("%d\n",ans[i]);
}

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

using namespace std;

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

int main()
{
	int H, W, N;
	cin >> H >> W >> N;

	int max_out = max(H, W);
	int attempts = 0;
	int count = 0;

	while(count < N)
	{
		count += max_out;
		attempts += 1;
		
	}
	cout << attempts << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    vector<int> cnt(4,0);
    for(int i = 0; i < 3; i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        cnt[a]++,cnt[b]++;
    }
    sort(cnt.begin(),cnt.end());
    if(cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 2 && cnt[3] == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(int i=0;i<p;i++)
#define ll long long

using namespace std;


//------------------素因数分解
vector<long long int> pri_fuc(long long int N){
	vector<long long int> p;
	for(long long int q=2;q*q<=N;q++){
		if(N%q == 0){
			while(N%q==0){
				p.push_back(q);
				N /= q;
			}
		}
	}
	if(N != 1){
		p.push_back(N);
	}
	return p;
}

int main(){

 ll int N;
 cin >> N;

 vector<ll int> A;

 A = pri_fuc(N);

 ll int a;
 a = A.size();

 ll int b=1;
 ll int counter=0;
 ll int counter2=0;
 ll int check=1;


 for(ll int i=0;i<a;i++){
if(i==11){
}
  if(A[i]!=b){
	  counter +=1;
	  b = A[i];
	  check = 1;
	  counter2 = 0;
  }
  else{
	  counter2 += 1;
	  if(check + 1==counter2){
		  counter+=1;
		  check += 1;
		  counter2 = 0;
	  }
	  else{}
  }

 }

 cout << counter;












	return 0;

}



Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    //	a / 13 = b ... c
    //	<=> a = 13 * b + c
    //	---> 10 * a + d = (13 * b + c) * 10 + d
    //
    //	10 * a + dを13でわったあまり
    //		<=> (13 * b + c) * 10 + dを13でわったあまり
    //		<=> 10 * c + dを13でわったあまり
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        String s = stdin.nextLine();

        long mod = 1_000_000_007;
        long[][] dp = new long[s.length() + 1][13];
        dp[0][0] = 1;
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < 13; j++) {
                if (s.charAt(i) == '?') {
                    for (int d = 0; d <= 9; d++) {
                        dp[i + 1][(10 * j + d) % 13] += dp[i][j];
                        dp[i + 1][(10 * j + d) % 13] %= mod;
                    }
                } else {
                    int x = s.charAt(i) - '0';
                    dp[i + 1][(10 * j + x) % 13] += dp[i][j];
                    dp[i + 1][(10 * j + x) % 13] %= mod;
                }
            }
        }

        System.out.println(dp[s.length()][5]);
    }

}


Measured memory_bytes: 40260
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {

    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      String str = br.readLine();
      if (str.length() == 2) {
        System.out.print(str);
      } else if (str.length() == 3) {
        System.out.print(new StringBuilder(str).reverse());
      }
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define Nmax 200005
#define OFF 100001
using namespace std;

long long n, x, v[Nmax], mn[Nmax];
long long fin, ans;

int main()
{
    cin >> n >> x;
    for (int i=1;i<=n;i++) cin >> v[i],mn[i] = v[i];
    fin = 1e18;
    for (int i=0;i<n;i++){
        ans = 0;
        for (int j=1;j<=n;j++){
            if (j-i > 0) mn[j] = min(mn[j], v[j-i]);
            else mn[j] = min(mn[j], v[n-(i-j)]);
            ans += mn[j];
        }
        ans += 1LL * x * i;
        fin = min(fin, ans);
    }
    cout << fin << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin>>N;
  string M  = N.substr(0,N.size()/2);
  bool ans = true;
  for(int i =0; i<N.size()/2; i++){
    for(int j = 0; j<M.size()/2; j++){
    if(N.at(i) != N.at(N.size()-1-i)||M.at(j) != M.at(M.size()-1-j)){
    ans = false;
    }
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
    else{
      cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

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

  if(n==1){
    cout << "! 1" << endl;
    return 0;
  }

  int bestd = -1, best = 0;
  // <d,idx>
  rep(i,n-1){
    cout << "? 1 " << i+2 << endl;
    int d;
    cin>>d;
    if(d > bestd){
      bestd = d;
      best = i+2;
    }
  }

  vector<int> ans(n,0);
  ans[0] = best;
  repl(i,1,n+1) if(i!=best){
    cout << "? " << best << " " << i << endl;
    int d;
    cin>>d;
    assert(ans[d]==0);
    ans[d] = i;
  }

  cout << "!";
  rep(i,n) cout << " " << ans[i];
  cout << endl;

  return 0;
}

Measured memory_bytes: 3624
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val D, N = sc.nextInt()

    val n = if (N == 100) 101 else N
    val ans = D match {
      case 0 => n
      case 1 => 100 * n
      case 2 => 10000 * n
    }

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}


Measured memory_bytes: 27324
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<bitset>
#include<deque>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define ri register int
#define il inline
#define fi first
#define se second
#define mp make_pair
#define pi pair<int,int>
#define mem0(x) memset((x),0,sizeof (x))
#define mem1(x) memset((x),0x3f,sizeof (x))
#define pb push_back
#define gc getchar
template<class T>void in(T &x)
{
    x = 0; bool f = 0; char c = gc();
    while (c < '0' || c > '9') {if (c == '-') f = 1; c = gc();}
    while ('0' <= c && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48); c = gc();}
    if (f) x = -x;
}
#undef gc
#define N 200010
#define M N<<3
#define int ll
struct Edge {
    int u, v, w, nx;
    Edge() {}
    Edge(int uu, int vv, int ww, int nxt) {
        u = uu, v = vv, w = ww, nx = nxt;
    }
    friend bool operator<(const Edge& a, const Edge& b) {
        return a.w < b.w;
    }
} edge[M];
int cnt, head[M];
il void add(int u, int v, int w) {
    edge[++cnt] = Edge(u, v, w, head[u]);
    head[u] = cnt;
}
int f[N];
int find(int x) {
    return x == f[x] ? x : f[x] = find(f[x]);
}
bool cmpy(int x, int y) {
    int fx = find(x), fy = find(y);
    if (fx == fy) return 0;
    if (fy > fx) f[fy] = fx;
    else f[fx] = fy;
    return 1;
}
int n, q;
int d[N];
signed main() {
    in(n), in(q);
    mem1(d);
    for (ri i = 1, a, b, c; i <= q; ++i) {
        in(a), in(b), in(c);
        add(a, b, c);
        d[a] = min(d[a], c + 1);
        d[b] = min(d[b], c + 2);
    }
    for (ri i = 0; i < n; ++i) {
        d[i] = min(d[i], d[(i - 1 + n) % n] + 2);
    }
    for (ri i = 0; i < n; ++i) {
        d[i] = min(d[i], d[(i - 1 + n) % n] + 2);
    }
    for (ri i = 0; i <= n; ++i) {
        add(i, (i + 1) % n, d[i]);
    }
    sort(edge + 1, edge + 1 + cnt);
    for (ri i = 1; i < n; ++i) f[i] = i;
    int lt = n, ans = 0;
    for (ri i = 1; i <= cnt && lt > 1; ++i) {
        if (cmpy(edge[i].u, edge[i].v)) {
            ans += edge[i].w;
            --lt;
        }
    }
    printf("%lld", ans);
    return 0;
}
//sdhdssgdh

Measured memory_bytes: 20736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int N = sc.nextInt();
			if (N == 0) {
				sc.close();
				break;
			}
			int M = sc.nextInt();
			int A = sc.nextInt();
			int B = sc.nextInt();
			int C = sc.nextInt();
			int T = sc.nextInt();

			// 行列をつくる
			// matrix[n]にはmatrixを2^n乗した行列が入ってる
			int[][][] matrix = new int[30][N + 2][N + 2];
			for (int i = 1; i <= N; ++i) {
				matrix[0][i][i - 1] = C;
				matrix[0][i][i] = B;
				matrix[0][i][i + 1] = A;
			}

			for (int n = 1; (1 << n) <= T; ++n) {
				for (int i = 1; i <= N; ++i) {
					for (int j = 1; j <= N; ++j) {
						for (int l = 1; l <= N; ++l) {
							matrix[n][i][j] += matrix[n - 1][i][l] * matrix[n - 1][l][j];
						}
						matrix[n][i][j] %= M;
					}
				}
			}

			int[][] c = new int[2][N + 2];
			for (int i = 1; i <= N; ++i) {
				c[0][i] = sc.nextInt();
			}

			int t = 0;
			for (int i = 0; (1 << i) <= T; ++i) {
				if ((T & (1 << i)) != 0) {
					for (int j = 1; j <= N; ++j) {
						c[1 - t][j] = 0;
					}
					for (int j = 1; j <= N; ++j) {
						for (int k = 1; k <= N; ++k) {
							c[1 - t][k] += c[t][j] * matrix[i][j][k];
						}
					}
					for (int j = 1; j <= N; ++j) {
						c[1 - t][j] %= M;
					}
					t = 1 - t;
				}
			}

			for (int i = 0; i < N; ++i) {
				if (i != 0) {
					System.out.print(" ");
				}
				System.out.print(c[t][i + 1]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 44012
import sys
from copy import deepcopy as copy
input = sys.stdin.readline


def main():
    h, w, m = map(int, input().split())
    
    bomb_h = [0]*h
    bomb_w = [0]*w
    bomb_w_place = [set() for _ in range(w)]
    for i in range(m):
        x, y = map(int, input().split())
        bomb_h[x-1] += 1
        bomb_w[y-1] += 1
        bomb_w_place[y-1].add(x-1)
    bomb_h2 = [0]*h
    for i in range(h):
        bomb_h2[i] = [bomb_h[i], i]
    bomb_h2.sort(reverse=True)
    
    ans = 0
    for i in range(w):
        index = 0
        key = bomb_w[i]
        k1, k2 = True, True
        ma = -1
        while index < len(bomb_h2):
            key2 = bomb_h2[index]
            if key2[1] in bomb_w_place[i]:
                if ma == -1:
                    ma = key2[0]-1
                    index += 1
                    continue
                elif ma == key2[0]-1:
                    index += 1
                    continue
                else:
                    break
            else:
                ma = max(ma, key2[0])
                break
            index += 1
        
        ans = max(ans, key+ma)
    print(ans)
        
    
    
if __name__ == "__main__":
    main()



Measured memory_bytes: 194824
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  long long K;
  scanf("%lld", &K);
  queue<ll> q;
  for (int i = 1; i < 10; ++i)
    q.push(i);
  for (int i = 0; i < K - 1; ++i)
  {
    ll x = q.front();
    q.pop();
    if (x % 10 != 0)
    {
      q.push(10 * x + x % 10 - 1);
    }
    q.push(10 * x + x % 10);
    if (x % 10 != 9)
    {
      q.push(10 * x + x % 10 + 1);
    }
  }
  cout << q.front() << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int gcd(int a,int b){
	if(a%b==0)
		return b;
	else
		return(gcd(b,a%b));
}
int main(void)
{
	long long int a,b;
	while(scanf("%lld %lld",&a,&b)>0){
        int lcm=(a*b)/gcd(a,b);
        if(lcm==0) break;
        printf("%lld %lld\n",gcd(a,b),lcm);
	}
	return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    int sum = 0;

    rep(i,N){
        int x;
        cin >> x;
        if (x < (K - x)){
            sum += 2 * x;
        } else {
            sum += 2 * (K - x);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    int taro = 0;
    int hanako = 0;
    for (int i = 0; i < n; i++) {
      String a = stdin.next();
      String b = stdin.next();
      if (a.compareTo(b) > 0) {
        taro += 3;
      } else if (a.compareTo(b) < 0) {
        hanako += 3;
      } else {
        taro++;
        hanako++;
      }
    }

    System.out.printf("%d %d%n", taro, hanako);
  }

}

Measured memory_bytes: 20832