akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, W;
	cin >> H >> W;

	vector<vector<int>> A(H, vector<int>(W));
	vector<vector<int>> B(H, vector<int>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> A[i][j];
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> B[i][j];

	const int offset = 6500;
	auto dp = make_vec(H + 1, W + 1, offset * 2 + 1, 0);
	dp[0][0][offset] = 1;
	for (int i = 0; i < H; i++) {

		for (int j = 0; j < W; j++) {

			for (int k = 0; k <= 2 * offset; k++) {

				if (0 <= k + A[i][j] - B[i][j] && k + A[i][j] - B[i][j] <= 2 * offset) {
					dp[i][j + 1][k] |= dp[i][j][k + A[i][j] - B[i][j]];
				}
				if (0 <= k - A[i][j] + B[i][j] && k - A[i][j] + B[i][j] <= 2 * offset) {
					dp[i][j + 1][k] |= dp[i][j][k - A[i][j] + B[i][j]];
				}
				
			}

		}
		DMP(dp);

		if (i == H - 1) break;
		for (int j = 1; j <= W; j++) {
			for (int k = 0; k <= 2 * offset; k++) {
				if (0 <= k + A[i + 1][j - 1] - B[i + 1][j - 1] && k + A[i + 1][j - 1] - B[i + 1][j - 1] <= 2 * offset) {
					dp[i+1][j][k] |= dp[i][j][k + A[i + 1][j - 1] - B[i + 1][j - 1]];
				}
				if (0 <= k - A[i + 1][j - 1] + B[i + 1][j - 1] && k - A[i + 1][j - 1] + B[i + 1][j - 1] <= 2 * offset) {
					dp[i+1][j][k] |= dp[i][j][k - A[i + 1][j - 1] + B[i + 1][j - 1]];
				}
			}
		}

		DMP(dp);

	}

	int ans = INF;
	for (int i = 0; i <= 2 * offset; i++) {
		if(dp[H - 1][W][i]) chmin(ans, abs(i - offset));
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 339968
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
int main(){
    string s, t;
    cin >> s >> t;
    s += s;
    rep(i, s.size()){
        for(int j=1;j <s.size(); j++){
            if (s.substr(i, j) == t){
              cout <<  "Yes" << endl;
              return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3212
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int x[1000];
int y[1000];
int r[1000];

inline int calc(int x1, int y1, int x2, int y2) {
  return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

bool in(int i, int ax, int ay) {
  return calc(ax,ay,x[i],y[i]) <= r[i]*r[i];
}

bool cmp(int a, int b) {
  return r[a] < r[b];
}

bool contain(int a, int b) {
  return calc(x[a],y[a],x[b],y[b]) < (r[a]-r[b])*(r[a]-r[b]);
}

bool intersect(int a, int b) {
  int d = calc(x[a],y[a],x[b],y[b]);
  return (r[a]-r[b])*(r[a]-r[b]) <= d &&
    d <= (r[a]+r[b])*(r[a]+r[b]);
}

int dp1[1001];
int dp2[1001];

int main() {
  int n;
  while(scanf("%d",&n),n) {
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    REP(i,n) scanf("%d%d%d",x+i,y+i,r+i);
    vector<int> v1,v2;
    REP(i,n) {
      bool f1 = in(i,sx,sy);
      bool f2 = in(i,tx,ty);
      if (f1 ^ f2) {
        if (f1) {
          v1.push_back(i);
        } else {
          v2.push_back(i);
        }
      }
    }
    sort(ALL(v1),cmp);
    sort(ALL(v2),cmp);
    REP(i,1001) dp1[i] = dp2[i] = 1;
    
    REP(i,v1.size()) {
      for (int j=i+1; j<v1.size(); ++j) {
        if (contain(v1[j],v1[i])) {
          chmax(dp1[j], dp1[i]+1);
        }
      }
    }
    REP(i,v2.size()) {
      for (int j=i+1; j<v2.size(); ++j) {
        if (contain(v2[j],v2[i])) {
          chmax(dp2[j], dp2[i]+1);
        }
      }
    }
    int ans = 0;
    REP(i,v1.size()) chmax(ans,dp1[i]);
    REP(i,v2.size()) chmax(ans,dp2[i]);

    // cout << "dp1 = "; REP(i,v1.size()) cout << dp1[i] << " "; cout << endl;
    // cout << "dp2 = "; REP(i,v2.size()) cout << dp2[i] << " "; cout << endl;

    REP(i,v1.size()) {
      REP(j,v2.size()) {
        if (!intersect(v1[i],v2[j])) {
          chmax(ans, dp1[i]+dp2[j]);
        }
      }
    }
    cout << ans << endl;
  }
}

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

using namespace std;

const int maxn=2e3+5;

typedef long long ll;

int num[maxn][maxn];

int top[maxn];

int vis[maxn];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		top[i]=1;
		for(int j=1;j<=n-1;j++){
			scanf("%d",&num[i][j]);
		}
	}
	int ans=0;
	while(1){
		int flg=0;
		memset(vis,0,sizeof(vis));
		for(int i=1;i<=n;i++){
			if(top[i]==n||vis[i]) continue;
			int tmp=num[i][top[i]];
			if(num[tmp][top[tmp]]==i&&!vis[tmp]){
				top[i]++;top[tmp]++;
				flg=1;
				vis[i]=1;vis[tmp]=1;
			}
		}
		if(!flg) break;
		ans++;
	}
	for(int i=1;i<=n;i++){
		if(top[i]!=n){
			printf("-1");return 0;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //Split line to array
        String[] data = br.readLine().split(" ");
        
        long A = Long.parseLong(data[0]);
        long B = Long.parseLong(data[1]);
        
        
        System.out.println(gcd(A, B));
    }
    static long gcd(long a, long b){
       if(a < b){
           long temp = a;
           a = b;
           b = temp;
       }
       if(b >0){
           return gcd(b,a % b);
       }else{
           return a;
       }
    }
}
      



Measured memory_bytes: 24364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<ll,ll>a,b;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		if(i%2){
			b[x]++;
		}
		else{
			a[x]++;
		}
	}
	vector<ll>A,B;
	A.push_back(0);
	B.push_back(0);
	ll ma=0;ll maA,maB;
	for(auto i=a.begin();i!=a.end();i++){
		ll key=i->first;
		ll val=i->second;
		if(ma<val){
			ma=val;
			maA=key;
		}
		A.push_back(val);
	}
	ma=0;
	for(auto i=b.begin();i!=b.end();i++){
		ll key=i->first;
		ll val=i->second;
		if(ma<val){
			ma=val;
			maB=key;
		}
		B.push_back(val);
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	reverse(A.begin(),A.end());
	reverse(B.begin(),B.end());
	if(maB!=maA){
		cout << n-A[0]-B[0];
		return 0;
	}
	else{
		ll ansma=max(A[0]+B[1],A[1]+B[0]);
		cout << n-ansma;
	}
	// your code goes here
	return 0;
}

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

int main(){
int n;
  string s;
  cin >>n;
  cin >>s;
  
  vector<int> a(s.size());
  
  
  for(int i;i<s.size();i++){
    
  if(s.at(i)=='A'){
    a.at(i)=0;
  }
  else if(s.at(i)=='B'){
    a.at(i)=1;
  }
  else if(s.at(i)=='C'){
    a.at(i)=2;
  }
      else if(s.at(i)=='D'){
    a.at(i)=3;
  }
      else if(s.at(i)=='E'){
    a.at(i)=4;
  }
      else if(s.at(i)=='F'){
    a.at(i)=5;
  }
      else if(s.at(i)=='G'){
    a.at(i)=6;
  }
      else if(s.at(i)=='H'){
    a.at(i)=7;
  }
      else if(s.at(i)=='I'){
    a.at(i)=8;
  }
      else if(s.at(i)=='J'){
    a.at(i)=9;
  }
      else if(s.at(i)=='K'){
    a.at(i)=10;
  }
      else if(s.at(i)=='L'){
    a.at(i)=11;
  }
      else if(s.at(i)=='M'){
    a.at(i)=12;
  }
      else if(s.at(i)=='N'){
    a.at(i)=13;
  }
      else if(s.at(i)=='O'){
    a.at(i)=14;
  }
      else if(s.at(i)=='P'){
    a.at(i)=15;
  }
      else if(s.at(i)=='Q'){
    a.at(i)=16;
  }
      else if(s.at(i)=='R'){
    a.at(i)=17;
  }
      else if(s.at(i)=='S'){
    a.at(i)=18;
  }
      else if(s.at(i)=='T'){
    a.at(i)=19;
  }
      else if(s.at(i)=='U'){
    a.at(i)=20;
  }
      else if(s.at(i)=='V'){
    a.at(i)=21;
  }
      else if(s.at(i)=='W'){
    a.at(i)=22;
  }
      else if(s.at(i)=='X'){
    a.at(i)=23;
  }
      else if(s.at(i)=='Y'){
    a.at(i)=24;
  }
      else if(s.at(i)=='Z'){
    a.at(i)=25;
  }
  }

  for(int i;i<s.size();i++){
    a.at(i)+=n;
    if(a.at(i)>=26){
    a.at(i)-=26;}
  }
  
  
    for(int i;i<s.size();i++){
    
  if(a.at(i)==0){
    s.at(i)='A';
  }
  else if(a.at(i)==1){
    s.at(i)='B';
  }
  else if(a.at(i)==2){
    s.at(i)='C';
  }
      else if(a.at(i)==3){
    s.at(i)='D';
  }
      else if(a.at(i)==4){
    s.at(i)='E';
  }
      else if(a.at(i)==5){
    s.at(i)='F';
  }
      else if(a.at(i)==6){
    s.at(i)='G';
  }
      else if(a.at(i)==7){
    s.at(i)='H';
  }
      else if(a.at(i)==8){
    s.at(i)='I';
  }
      else if(a.at(i)==9){
    s.at(i)='J';
  }
      else if(a.at(i)==10){
    s.at(i)='K';
  }
      else if(a.at(i)==11){
    s.at(i)='L';
  }
      else if(a.at(i)==12){
    s.at(i)='M';
  }
      else if(a.at(i)==13){
    s.at(i)='N';
  }
      else if(a.at(i)==14){
    s.at(i)='O';
  }
      else if(a.at(i)==15){
    s.at(i)='P';
  }
      else if(a.at(i)==16){
    s.at(i)='Q';
  }
      else if(a.at(i)==17){
    s.at(i)='R';
  }
      else if(a.at(i)==18){
    s.at(i)='S';
  }
      else if(a.at(i)==19){
    s.at(i)='T';
  }
      else if(a.at(i)==20){
    s.at(i)='U';
  }
      else if(a.at(i)==21){
    s.at(i)='V';
  }
      else if(a.at(i)==22){
    s.at(i)='W';
  }
      else if(a.at(i)==23){
    s.at(i)='X';
  }
      else if(a.at(i)==24){
    s.at(i)='Y';
  }
      else if(a.at(i)==25){
    s.at(i)='Z';
  }
  }
  
  
  cout<<s<<endl;
  
  
return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;


signed main() {
    int N;
    cin >> N;
    vector<int> a(3 * N);
    cin >> a;
    multiset<int> setLeft, setRight;
    multiset<int> dashLeft, dashRight;
    int sumLeft = 0, sumRight = 0;
    for (int i = 0; i < 3 * N; i++) {
        if (i < N) dashLeft.insert(a[i]);
        else setRight.insert(a[i]);
    }
    sumLeft = accumulate(dashLeft.begin(), dashLeft.end(), 0LL);
    {
        auto itr = setRight.begin();
        for (int i = 0; i < N; i++) {
            dashRight.insert(*itr);
            sumRight += *itr;
            itr = setRight.erase(itr);
        }
    }
    int ans = sumLeft - sumRight;
    for (int i = N; i < 2 * N; i++) {
        {
            // left
            int dif = a[i] - *dashLeft.begin();
            if (dif > 0) {
                sumLeft += dif;
                dashLeft.erase(dashLeft.begin());
                dashLeft.insert(a[i]);
            }
        }
        {
            // right
            int dif = -a[i];
            if (dashRight.find(a[i]) != dashRight.end()) {
                dashRight.erase(dashRight.find(a[i]));
                dif += *setRight.begin();
                sumRight += dif;
                dashRight.insert(*setRight.begin());
                setRight.erase(setRight.begin());
            } else setRight.erase(setRight.find(a[i]));
        }
        ans = max(ans, sumLeft - sumRight);
    }
    cout << ans << endl;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n; cin>>n;
	vector<ll> a(n+1,1);
	a[1]=1;
	rep(i,2,n+1){
		if(a[i]!=1) continue;
		ll j=i;
		while(j<=n){
			ll now=j;
			ll cnt=1;
			while(now%i==0){
				now/=i;
				cnt++;
			}
			a[j]*=cnt;
			j+=i;
		}
	}
	// rep(i,1,n+1) debug(a[i]);
	ll ans=0;
	rep(i,1,n+1){
		ans+=i*a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 81368
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int[] number = new int[3];
		for(int i=0; i<3; i++){
				number[i] = in.nextInt();	
		}

		number = bubbleSort(number);
		System.out.println(number[0]+" "+number[1]+" "+number[2]);
	}

	public static int[] bubbleSort(int[] number){
		for(int i=0; i<number.length-1; i++){
			for(int j=0; j<number.length-1; j++){
				if(number[j] > number[j+1]){
					int temp = number[j];
					number[j] = number[j+1];
					number[j+1] = temp;
				}
			}
		}
		return number;
	}
}

Measured memory_bytes: 26252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp16
{
     class Program
    {
        public static void Main()
        {
            while (true)
            {
                string a = Console.ReadLine();
                if (a == null) break;
                decimal[] b= a.Split().Select(decimal.Parse).ToArray();//1 2 3 4 5 6
                decimal[] c = {b[1]*b[3]/b[0],b[2]*b[3]/b[0]};//8 12
                decimal d =( b[5] - c[1]) / (b[4] - c[0]);//-6 -3
                decimal e = (b[2] - d*b[1]) / b[0];//3 2
                Console.WriteLine("{0,0:F3} {1,1:F3}",e,d);
            }
        }
    }
}

Measured memory_bytes: 9688
s = input()
x, y = map(int, input().split())

def cul(x_axis,x):
    dic={0:1}
    for i in range(len(x_axis)):
        tmp={}
        for j in dic:
            tmp[j+x_axis[i]]=1
            tmp[j-x_axis[i]]=1
        dic=tmp
    if x in dic: return True
    else: return False

s_split = [len(item) for item in s.split("T")]

x_axis = s_split[0::2]
y_axis = s_split[1::2]

if s[0]=="F": x=abs(x-x_axis.pop(0))
y=abs(y)

print("Yes" if cul(x_axis,x) and cul(y_axis,y) else "No")

Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define fast_read ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;
int main()
{
    fast_read

    ll n,x,z;
    cin>>n>>x>>z;
    ll a[n];
    for (ll i = 0;i<n;i++)cin>>a[i];
    ll st = 0;
    char e = 'x';
    ll o = abs(a[n - 1] - z);
    while (true) {
        if (e == 'x') {
            ll need = st,mx = INT_MIN;
            for (ll i = st;i<n;i++) {
                if (i == n - 1 && abs(a[i] - z) >= mx) need = i;
                else if (i != n - 1) {
                    ll mn = INT_MAX;
                    for (ll j = i + 1;j<n;j++) {
                        if (abs(a[j] - a[i]) < mn) mn = abs(a[j] - a[i]);
                    }
                    if (mn > mx) {
                        need = i;
                        mx = mn;
                    }
                }
            }
            x = a[need];
            //cout<<e<<" "<<x<<" "<<z<<endl;
            if (need == n - 1)break;
            else st = need + 1;
            e = 'y';
        }
        else {
            ll need = st,mn = INT_MAX;
            for (ll i = st;i<n;i++) {
                if (i == n - 1 && abs(a[i] - x) <= mn) need = i;
                else  if (i != n - 1) {
                    ll mx = INT_MIN;
                    for (ll j = i + 1;j<n;j++) {
                        if (abs(a[j] - a[i]) > mx) mx = abs(a[j] - a[i]);
                    }
                    if (mx < mn) {
                        need = i;
                        mn = mx;
                    }
                }
            }
            //cout<<need<<endl;
            z = a[need];
            //cout<<e<<" "<<x<<" "<<z<<endl;
            if (need == n - 1)break;
            else st = need + 1;
            e = 'x';
        }
    }
    cout<<max(o,abs(x - z))<<endl;
    return 0;
}
/*
5 50 100
50 100 50 50 50
*/

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

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

    map<pair<int, int>, int> mp;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        a--;
        mp[make_pair(min(i, a), max(i, a))]++;
    }

    int ans = 0;
    for (auto p : mp) {
        if (p.second == 2) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 6528
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    while (true) {
        int d, n, m;
        cin >> d;
        if (d == 0) break;
        cin >> n >> m;

        int D[n + 1];
        D[0] = 0;
        D[n] = d;
        for (int i = 1; i < n; i++) cin >> D[i];

        sort(D, D + n + 1);

        int ret = 0;

        for (int i = 0; i < m; i++) {
            int dest;
            cin >> dest;

            int *bigger = lower_bound(D, D + n + 1, dest);
            int dist = abs(dest - *bigger);
            if (bigger - D > 0) {
                dist = min(dist, abs(dest - *(bigger - 1)));
            }

            ret += dist;
        }

        cout << ret << endl;
    }

    return 0;
}


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

int main()
{
  int N ;
  cin>>N ;
  vector<int>t(N+1),x(N+1),y(N+1) ;
  for(int i=0;i<N+1;i++){
    if(i==0) t.at(i)=0,x.at(0)=0,y.at(0)=0 ;
    else cin>>t.at(i)>>x.at(i)>>y.at(i) ;
  }
  
  int T,X,Y ;
  for(int i=1;i<N+1;i++){
    T=t.at(i)-t.at(i-1) ;
    X=x.at(i)-x.at(i-1) ;
    Y=y.at(i)-y.at(i-1) ;
    
    if(T<X+Y||(T-X-Y)%2!=0){
      cout<<"No"<<endl ;
      return 0 ;
    }
    
  }
  cout<<"Yes"<<endl ;
  return 0 ;
}

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

// segument tree, RMQ
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        SegmentTree st = new SegmentTree(n);
        for (int i = 0; i < q; i++) {
            int com = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (com == 1) {
                System.out.println(st.find(x, y + 1));
            } else {
                st.update(x, y);
            }
        }
    }

    static class SegmentTree {
        int[] data;
        int n;
        static int INF = (1 << 31) - 1;

        SegmentTree(int n_) {
            n = 1;
            while (n < n_) {
                n *= 2;
            }
            data = new int[2 * n - 1];

            Arrays.fill(data, INF);
        }

        int find(int a, int b) {
            return find(a, b, 0, 0, 0);
        }

        int find(int a, int b, int k, int l, int r) {
            if (r <= l) {
                r = n;
            }
            if (r <= a || b <= l) {
                return INF;
            }
            if (a <= l && r <= b) {
                return data[k];
            }
            int vl = find(a, b, k * 2 + 1, l, (r + l) / 2);
            int vr = find(a, b, k * 2 + 2, (r + l) / 2, r);
            return Math.min(vl, vr);
        }

        void update(int k, int a) {
            k += n - 1;
            data[k] = a;
            while (k > 0) {
                k = (k - 1) / 2;
                data[k] = Math.min(data[k * 2 + 1], data[k * 2 + 2]);
            }
        }
    }
}

Measured memory_bytes: 104240
fun main(arr: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val isAC = (1..n).map { false }.toMutableList()
    val countWa = (1..n).map { 0 }.toMutableList()
    for(i in (1..m)) {
        val inpt = readLine()!!.split(" ")
        val idx = inpt[0].toInt()-1
        if(inpt[1] == "AC") {
            isAC[idx] = true
        } else if(!isAC[idx]) {
            countWa[idx]++
        }
    }
    isAC.indices.filter { !isAC[it] }.forEach { countWa[it] = 0 }
    println("${isAC.count { it }} ${countWa.sum()}")
}

Measured memory_bytes: 60968
import string

alphabet = string.ascii_lowercase

S = str(input())
T = str(input())
start = [-1 for i in range(len(alphabet))]
goal = [-1 for i in range(len(alphabet))]
tf = True

for i in range(len(S)):
    a = alphabet.index(S[i])
    b = alphabet.index(T[i])

    if (start[a] != -1 or goal[b] != -1):
        if (start[a] != b or goal[b] != a):
            tf = False
            break
    else:
        start[a] = b
        goal[b] = a

if tf:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4160
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i = 0 ; i < n ; i++) d[i] = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for(int i = 0 ; i < n ; i++) {
			set.add(d[i]);
		}
		System.out.println(set.size());
	}
}


Measured memory_bytes: 25812
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

Measured memory_bytes: 7728
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void) {
	string S;
	cin >> S;
	bool ans =true;
	for (int i = 1; i < (int) S.length(); i++) {
		if (S[i] == S[i - 1]) ans = false;
	}
	printf(ans ? "Good" : "Bad");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
unsigned short *A, *B;

int C[VMAX+1];
int n, i, j;
scanf("%d", &n);

A = malloc(sizeof(short)*n+1);
B = malloc(sizeof(short)*n+1);

for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

for ( i = 0; i < n; i++ ){
  scanf("%hu", &A[i + 1]);
  C[A[i + 1]]++;
}

for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

for ( j = 1; j <= n; j++ ){
  B[C[A[j]]] = A[j];
  C[A[j]]--;
}

for ( i = 1; i <= n; i++ ){
  if ( i > 1 ) printf(" ");
  printf("%d", B[i]);
}
printf("\n");

return 0;
}

Measured memory_bytes: 8464
// https://atcoder.jp/contests/abc043/tasks/abc043_a
#include <iostream>

#define toDigit(c) (c-'0')
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define _ std::ios::sync_with_stdio(false); std::cin.tie(0);
#define debug(x) std::cout << '>' << #x << ':' << x << std::endl;

typedef long long LL;

int main() { _
  int n;
  std::cin >> n;

  int acc = 0;
  for(int i=1; i<=n; i++)
    acc += i;

  std::cout << acc << '\n';

  return 0;
}


Measured memory_bytes: 3140
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MF(int s,int t,int e,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,e,MIN(min,co[i]));
    co[i]-=r;
    co[(i+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
//呼び出す方
//sからtへの最大流を求める　ノード数v辺の数e　aからbへキャパcのフローが流れる
int maxf(int s,int t,int v,int e,int *a,int *b,int *c){
  int i,f,r;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];
    co[ta[b[i]]=i+e]=0;
  }
  for(f=0;r=MF(s,t,e,1000000000);f+=r){
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int CO[100010];
void dijk(int v,int e,int *fr,int *to,int *co,int mi){
  int i,id[100010],ta[100010],nt[100010],f[100010]={0};
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<v;i++)CO[i]=1000000000;
  for(i=CO[mi]=0;i<e;i++){
    nt[i  ]=ta[fr[i]];
    ta[fr[i]]=i;
  }
  while(f[mi]-1){
    f[mi]=1;
    for(i=ta[mi];i+1;i=nt[i]){
      if(CO[to[i]]>CO[mi]+co[i])hin(CO[id[R]=to[i]]=CO[mi]+co[i]);
    }
    while(f[mi]&&C-1)mi=id[hout()];
  }
}
int main(){
  int a[4010],b[4010],c[4010],d[4010],n,m,s,t,i;
  int aa[4010],bb[4010],cc[4010],r=0;
  scanf("%d %d %d %d",&n,&m,&s,&t);
  for(i=0;i<m;i++)scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
  /*for(i=0;i<m;i++){
    a[i+m]=b[i];
    b[i+m]=a[i];
    c[i+m]=c[i];
    d[i+m]=d[i];
    }//*/
  dijk(n+1,m,a,b,c,s);
  //for(i=0;i<n;i++)printf("%d ",CO[i+1]);printf("\n\n");
  r=0;
  for(i=0;i<m;i++){//printf("%d %d %d\n",a[i],b[i],c[i]);
    if(CO[a[i]]+c[i]==CO[b[i]]){//printf("OK\n");
      aa[r  ]=a[i];
      bb[r  ]=b[i];
      cc[r++]=d[i];
    }
  }//printf("%d\n",r);
  printf("%d\n",maxf(s,t,n+1,r,aa,bb,cc));
  return 0;
}



Measured memory_bytes: 2316
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
 int n,a=0,w=0,t=0,r=0;
  cin>>n;
  while(n--){
    cin>>s;
    if(s=="AC"){
      a++;}
    else if(s=="WA"){
      w++;}
    else if(s=="TLE"){
	t++;}
    else{
      r++;}
  }
  cout<<"AC "<<"x "<<a<<"\n";
    cout<<"WA "<<"x "<<w<<"\n";
    cout<<"TLE "<<"x "<<t<<"\n";
    cout<<"RE "<<"x "<<r<<"\n";
  return 0;
}


Measured memory_bytes: 3628
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

template <ll mod> class ModInt {
    ll a;
public:
    constexpr ModInt(const ll a = 0) noexcept : a((a % mod + mod) % mod) {}
    constexpr ll &value() noexcept { return a; }
    constexpr ModInt operator + (const ModInt &rhs) const noexcept { return ModInt(*this) += rhs; }
    constexpr ModInt operator - (const ModInt &rhs) const noexcept { return ModInt(*this) -= rhs; }
    constexpr ModInt operator * (const ModInt &rhs) const noexcept { return ModInt(*this) *= rhs; }
    constexpr ModInt operator / (const ModInt &rhs) const noexcept { return ModInt(*this) /= rhs; }
    constexpr ModInt &operator += (const ModInt &rhs) noexcept {
        a += rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator -= (const ModInt &rhs) noexcept {
        a += mod - rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator *= (const ModInt &rhs) noexcept {
        a = a * rhs.a % mod;
        return *this;
    }
    constexpr ModInt pow(ll t) const noexcept {
        if (t == 0) return 1;
        auto ret = pow(t >> 1);
        ret *= ret;
        if (t & 1) ret *= *this;
        return ret;
    }
    constexpr ModInt inv() const noexcept { return pow(mod - 2); }
    constexpr ModInt operator /=(const ModInt &rhs) { return (*this) *= rhs.inv(); }
    constexpr bool operator == (const ModInt &rhs) const noexcept { return this->a == rhs.a; }
    constexpr bool operator != (const ModInt &rhs) const noexcept { return this->a != rhs.a; }
    friend constexpr ostream &operator << (ostream &os, const ModInt &rhs) noexcept { return os << rhs.a; }
    friend constexpr istream &operator >> (istream &is, ModInt &rhs) {
        is >> rhs.a;
        return is;
    }
};
using mint = ModInt<MOD>;

class Combination {
public:
    vector <mint> fac, inv, fiv;
    Combination(int N) : fac(N + 1), inv(N + 1), fiv(N + 1) {
        fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
        for (ll i = 2; i <= N; i++) {
            fac[i] = fac[i - 1] * i; // n!
            inv[i] = inv[MOD % i] * (MOD - MOD / i); // n^-1
            fiv[i] = fiv[i - 1] * inv[i]; // (n!)^-1
        }
    }
    mint C(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[k] * fiv[n - k];
    }
    mint P(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[n - k];
    }
    mint H(ll n, ll k) {
        if (n == 0 && k == 0) return 1;
        return C(n + k - 1, k - 1);
    }
};

int main() {
    ll n, k;
    cin >> n >> k;
    Combination com(1005);
    cout << com.P(k, n) << endl;
    return 0;
}


Measured memory_bytes: 3136
--Structured Program II - Spreadsheet

import Control.Applicative
import Data.List (transpose)

main :: IO ()
main = do
  [r, _] <- map read . words <$> getLine
  xs <- take r . map (map read . words) . lines <$> getContents
  mapM_ (putStrLn . unwords . map show) $ spreadSheet xs

spreadSheet :: [[Int]] -> [[Int]]
spreadSheet xs = (f . f) xs
  where f xs = map (\x -> x ++ [sum x]) $ transpose xs



Measured memory_bytes: 7556
N, M = map(int, input().split())
a = []
b = []
c = []
d = []
ans = []

for n in range(N):
  A, B = map(int, input().split())
  a.append(A)
  b.append(B)

for m in range(M):
  C, D = map(int, input().split())
  c.append(C)
  d.append(D)

for i in range(N):
  l = []
  for j in range(M):
    l.append(abs(a[i] - c[j]) + abs(b[i] - d[j]))
  print(l.index(min(l))+1)

Measured memory_bytes: 9060
import scala.io.Source.stdin

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<5000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]):Unit = {
    println(stdin.getLines.drop(1).count{x => isPrime(x.toInt)})
  }
}

Measured memory_bytes: 68308
N = int(input())
A = list(map(int, input().rstrip().split()))
A.sort()
ANS = 2**(N//2)

if N%2 == 0:
    if A[0] and A[1] != 1:
        print(0)
        exit()
    elif N == 2:
        if A[0] != A[1]:
            print(0)
            exit()
    else:
        for i in range(2,N,2):
            if A[i] != A[i+1] or A[i] - A[i-2] != 2:
                print(0)
                exit()
else:
    if A[0] != 0:
        print(0)
        exit()
    elif N == 3:
        if A[1] != A[2]:
            print(0)
            exit()
    else:
        for i in range(3,N,2):
            if A[i] != A[i+1] or A[i] - A[i-2] != 2:
                print(0)
                exit()

print(ANS%(10**9+7))


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

#define ll long long
#define inf pow(10,18);

vector<ll> arr;
vector<vector<ll>> dp;
vector<vector<ll>> cost;

pair<ll,ll> help(int i,int j) {
    if(i>j) return {0,0};
    if(i==j) {
        dp[i][j]=arr[i];
        cost[i][j]=dp[i][j];
        return {0,dp[i][j]};
    }
    if(cost[i][j]!=-1) return { cost[i][j],dp[i][j] };

    ll mn=inf;
    for(int x=i;x<j;x++) {
        auto p1= help(i,x), p2= help(x+1,j);
        dp[i][j]= p1.second+ p2.second;
        mn= min( p1.first+ p2.first + dp[i][j], mn );
    }
    cost[i][j]=mn;
    return {cost[i][j],dp[i][j]};
}

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

    arr.resize(n);
    dp.resize(n,vector<ll>(n,-1));
    cost.resize(n,vector<ll>(n,-1));
    for(int i=0;i<n;i++) cin>>arr[i];
    auto x=help(0,n-1);
    cout<<x.first;
    return 0;
}

Measured memory_bytes: 2816
// Problem : D - Integer Cards
// Contest : AtCoder - AtCoder Beginner Contest 127
// URL : https://atcoder.jp/contests/abc127/tasks/abc127_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//look at my code
//my code is amazing
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<nl
#define cout2(a,b) cout<<a<<" "<<b<<nl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<nl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<nl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<nl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define maxi(a,b,c) max(a,max(b,c))
#define maxii(a,b,c,d) max(max(a,b),max(c,d))
#define mini(a,b,c) min(a,min(b,c))
#define md(a,b)  ((a%mod)*(b%mod)+mod)%mod 
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
// const int N=;
bool comp(pll a,pll b){
	if(a.y==b.y)
	return a.x<b.x;
	
	return a.y>b.y;
}
int32_t main()
{
    
	fast
	ll n,m;
	cin>>n>>m;
	ll a[n];
	f(i,n){
		cin>>a[i];
	}
	
	sort(a,a+n);
	ll ptr=0;
	ll ans=0;
	pll cc[m];
	f(i,m){
		cin>>cc[i].x>>cc[i].y;
	}
	
	sort(cc,cc+m,comp);
	f(i,m){
		ll c,v;
		c=cc[i].x;
		v=cc[i].y;
		ll pos=lower_bound(a+ptr,a+n,v)-a;
		// trace(pos);
		if(pos==ptr)
		continue;
		ll x=min(pos-ptr,c);
		ans+=x*v;
		ptr+=x;
		
	}
	// trace(ptr);
	for(ll i=ptr;i<n;i++)
	ans+=a[i];
	
	
	
	cout1(ans);
	



    

	return 0;
    
}

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

int main(void){
	int n, m;
	while(true){
		cin >> n >> m;
		if(!n&&!m) break;
		vector<int> a(n);
		for(int i = 0; i < n; ++i){
			cin >> a[i];
		}
		int ans = 0, sum;
		for(int i = 0; i < n-1; ++i){
			for(int j = i+1; j < n; ++j){
				sum = a[i] + a[j];
				if(sum > m) continue;
				ans = max(sum, ans);
			}
		}
		if(ans){
			cout << ans << endl;
		}else{
			cout << "NONE" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i,n) for(int i=n-1;i>=0;i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
 

signed main(){
   
   int a,b;
   cin>>a>>b;
   if(a==b)cout<<a*2<<endl;
   else cout<<max(a,b)*2-1<<endl;
}


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

int main(void){
    ll n, k;
    cin>>n>>k;
    ll ans;
    if(n>=k){
        ans=min(n%k, k-n%k);
    }
    else{
        ans=min(k-n, n);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
class Main {
  	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str1 = br.readLine();
		String str2 = br.readLine();
		int[] x = new int[4];
		LinkedList<Integer> a = new LinkedList<Integer>();
		
		if(str1.indexOf(str2) == -1){
			return;
		}
		if(str1.equals(str2)){
			System.out.println("0");
			return;
		}
		
		
		a.add(str1.indexOf(str2));
		int i = 1;
		while(str1.indexOf(str2, a.get(i - 1) + 1) != -1){
			a.add(str1.indexOf(str2, a.get(i - 1) + 1));
			i++;
		}
		
		for(int j = 0; j < a.size(); j++){
			System.out.println(a.get(j));
		}
	}
}

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

int main(){
    int N;
    cin >> N;
    vector<pair<string, int>> P(N);
    for (int i = 0; i < N; i++){
        string S;
        int N;
        cin >> S >> N;
        P.at(i) = make_pair(S, N);
    }
    vector<int> Q(N);
    for (int i = 0; i < N; i++){
        int num_i = 1;
        string S_i;
        S_i = P.at(i).first;
        int P_i;
        P_i = P.at(i).second;
        for (int j = 0; j < N; j++){
            if (P.at(j).first < S_i){
                num_i++;
            }
            else if(P.at(j).first == S_i && P.at(j).second > P_i){
                num_i++;
            }
        }
        Q.at(i) = num_i;
    }
    // ここまでi個目のレストランが何番目に出てくるかを出力している（勘違い）
    for (int i = 1; i <= N; i++){
        for (int j = 0; j < N; j++){
            if (Q.at(j) == i){
                cout << j + 1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
t,a = li()
h = list(li())

temp_list = []

for i in range(n):
    temp_list.append(t - h[i]*0.006)
 
ans = 10**18
for j, temp in enumerate(temp_list):
    if abs(a-temp) < ans:
        point = j
        ans = abs(a-temp)
        
print(point+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int dp[1005],x[1005],t[1005][5005][2],n;
vector<int>edge[1005];
void dfs(int v,int u){
	rep(i,edge[v].size()){
		if(edge[v][i]==u) continue;
		dfs(edge[v][i],v);
	}
	rep(i,5005) t[v][i][0] = t[v][i][1] = INF;
	t[v][0][0] = 0; int cur = 0;
	rep(i,edge[v].size()){
		if(edge[v][i]==u) continue;
		rep(ii,5005) t[v][ii][1-cur] = INF;
		for(int j=x[v];j>=0;j--){
			int a = x[edge[v][i]],b = dp[edge[v][i]]; //if(j==0)cout<<a<<b<<endl;
			if(j>=a) t[v][j][1-cur] = min(t[v][j][1-cur],t[v][j-a][cur]+b);
			swap(a,b);
			if(j>=a) t[v][j][1-cur] = min(t[v][j][1-cur],t[v][j-a][cur]+b);
		}
		cur^=1;
	}
	rep(j,x[v]+1){
		dp[v] = min(dp[v],t[v][j][cur]);
	}
//	cout<<dp[v]<<v<<endl;
}
int main(){
	cin>>n;
	for(int i=2;i<=n;i++){
		int a; scanf("%d",&a);
		edge[i].pb(a);
		edge[a].pb(i);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&x[i]);
	}
	fill(dp,dp+1005,INF);
	dfs(1,-1);//cout<<dp[1]<<dp[2]<<dp[3]<<endl;
	if(dp[1] > 100000000) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
}

Measured memory_bytes: 39424
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 998244353;

char s[15][1005];

int main(){
	ll h,w,k; cin >> h >> w >> k;
	rep(i,h) rep(j,w) cin >> s[i][j];
	ll answer = inf;
	rep(bit,1<<(h-1)){
		ll ans = 0;
		rep(i,h-1){
			if(bit>>i & 1) ans++;
		}
		ll num = ans;
		vl group(num+1,0);
		vl nxt(num+1,0);
		bool f = true;
		rep(j,w){
			ll id = 0;
			rep(i,h){
				if(s[i][j]=='1') nxt[id]++;
				if(i<h-1 && (bit>>i & 1)) id++;
			}
			bool flag = true;
			rep(i,num+1){
				if(nxt[i] > k){
					f = false;
					break;
				}
				if(group[i] + nxt[i] > k){
					flag = false;
				}
			}
			if(!f) break;
			rep(i,num+1){
				if(flag) group[i] += nxt[i];
				else group[i] = nxt[i];
				nxt[i] = 0;
			}
			if(!flag) ans++;
		}
		if(f) chmin(answer,ans);
		else continue;
	}
	cout << answer << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int a,b,k,x;// 5 2 3
    scanf ("%lld",&a);
    scanf ("%lld",&b);//2 3 3
    scanf ("%lld",&k);
    x=a;//5
    a=a-k;//2
    k=k-x;//3-5=-2
    if (a<0)
    {
        a=0;
    }
    if (k>0 && b>0)
    {
        b=b-k;
        if (b<0)
        {
            b=0;
        }
    }
    printf ("%lld %lld\n",a,b);
}


Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <valarray>
#include <iterator>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <list>
#include <map>
#include <strstream>
#include <streambuf>
#include <string>
#include <sstream>
//#include "graph.cpp"

#define vi vector<int>
#define vii vector< pair<int,int> >
#define last(arr) arr.size()-a
#define loop(i,n) for(ll i=0 ; i<n ; ++i)
#define all(v) ((v).begin()),((v).end())
#define pb push_back
#define ll long long
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)

using namespace std;
char arr[55][55];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1 ; i<=n ;i++){
        for(int j=1 ; j<=m ;j++){
            cin>>arr[i][j];
        }
    }
    for(int i=1 ; i<=n ;i++){
        for(int j=1 ; j<=m ;j++){
            if(arr[i][j]=='#'){
                if(arr[i][j-1] != '#' && arr[i][j+1] != '#' &&
                   arr[i+1][j] != '#' &&arr[i-1][j] != '#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{
    while (1)
    {
        long long h, w;
        cin >> h >> w;
        if (h == 0 && w == 0)
        {
            break;
        }
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (i == 0 || i == h - 1)
                {
                    cout << '#';
                }
                else
                {
                    if (j == 0 || j == w - 1)
                    {
                        cout << '#';
                    }
                    else
                    {
                        cout << '.';
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
main()
{
	lli k;
	cin>>k;
	
	if(k%2 == 0)
		cout<<"-1\n";
	else if(k%5 == 0)
		cout<<"-1\n";
	else
	{
		int count = 0;
		lli cons = 7;
		while(1)
		{
			count++;
			cons =  (cons*10)%(k*9);
			if(cons == 7%(9*k))
				break;
			
		}
		cout<<count<<"\n";
	}		
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


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


    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    char p = 'A';
    for (char c : s) {
        if (c != p) {
            ans++;
            p = c;
        }
    }

    cout << ans;




}

Measured memory_bytes: 512