akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
 
int GCD(int ,int);
 
int main(void){
 
  	int N,M;
	long long int G,i,n,m;
	char *S,*T;
  
	scanf("%d %d",&N,&M);
	S = (char *)malloc((N+1)*sizeof(char));
	T = (char *)malloc((M+1)*sizeof(char));
	scanf("%s",S);
	scanf("%s",T);
 
	G = GCD(N,M);
  	n = N/G;
  	m = M/G;
 
	for(i=0;i<G;i++){
    	if(S[i*n] != T[i*m]){
 			printf("-1\n");       	
			free(S);
			free(T);
			return 0;
        }
    }
  
	printf("%lld\n",(long long int)(N/G*M));
 
	free(S);
	free(T);
	return 0;
}
 
 
int GCD(int a,int b){
	
	int tmp,r;
	
	if(a<b){
		tmp = a;
		a = b;
		b = tmp;
	}
	
	r = a % b;
	
	while(r != 0){
		a = b;
		b = r;
		r = a % b;
	}
  	return b;
 
}

Measured memory_bytes: 352
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: &str = iterator.next().unwrap();

    let mut s1 = String::new();
    let mut s2 = String::new();
    for i in 0..s.len() {
        s1.push(if i % 2 == 0 { '0' } else { '1' });
        s2.push(if i % 2 == 0 { '1' } else { '0' });
    }

    let mut count1 = 0;
    let mut count2 = 0;

    let mut it = s.chars();
    let mut it1 = s1.chars();
    let mut it2 = s2.chars();
    for _i in 0..s.len() {
        let c = it.next().unwrap();
        let c1 = it1.next().unwrap();
        let c2 = it2.next().unwrap();
        if c != c1 {
            count1 += 1;
        }
        if c != c2 {
            count2 += 1;
        }
    }

    return format!("{}", min(count1, count2));
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
  int key;
  struct node *parent,*left,*right;
}Node;

Node *root,*NIL;

void Insert(int);
void Inorder(Node *);
void Preorder(Node *);

int main(){
  int m,i,k;
  char com[20];

  scanf("%d",&m);

  for(i=0; i<m; i++){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&k);
      Insert(k);
    }
    else if(com[0] == 'p'){
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }

    return 0;
}
  
void Insert(int k){
  Node *y = NIL;            
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }

  z->parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

void Inorder(Node *r){
  if(r != NIL){
    Inorder(r->left);
    printf(" %d",r->key);
    Inorder(r->right);
  }
}

void Preorder(Node *r){
  if(r != NIL){
    printf(" %d",r->key);
    Preorder(r->left);
    Preorder(r->right);
  }
}

Measured memory_bytes: 24040
N, M = map(int, input().split())
X = list(map(int, input().split()))

X = list(set(X))
X.sort()
M = len(X)
L = [X[i+1] - X[i] for i in range(len(X)-1)]
L.sort()

if M <= N:
    print(0)
else:
    print(sum(L[:(M-N)]))


Measured memory_bytes: 14936
// Problem : D - Not Divisible
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define dbp(x) cout<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define dbv(v) {cout<<#v<<" : ";for (auto x:v) cout<<x<<' ';cout<<endl;}
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
#define die(x) return cout<<x<<'\n', 0;

using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;

int32_t main()
{
fastio;

int testcases;
testcases=1;
//cin>>testcases;

while(testcases--)
{
	int n;
	cin>>n;
	vector<int> vec(n);
	map<int,int> mp;
	rep(i,0,n-1)
		{
			cin>>vec[i];
			mp[vec[i]]++;
		}
	map<int,int> flag;
	int ans=0;	
	for(auto it: mp)
	{
		if(it.second>1)
		{
			flag[it.first]=-1;
		}
		else
		{
			flag[it.first]=0;			
			int num=it.first;
			bool b=true;
			for(int i=1; i*i<=num; i++)
			{
				if(num%i==0)
				{
					if(i!=num&&mp.count(i))
					{
						b=false;
						break;
					}	
					if((num/i)!=num&&mp.count(num/i))
					{
						b=false;
						break;
					}				
				}			
			}
			if(b)
			{
				ans++;
				flag[it.first]=1;
			}	
		}
	}
		cout<<ans<<'\n';	
}

return 0;
}


Measured memory_bytes: 29844
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if(A < B){
    if(B-A > X){
      cout << "dangerous" << endl;
    }
    else{
      cout << "safe" << endl;
    }
  }
  else{
    cout << "delicious" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		//System.out.println( moji.indexOf('C'));
		//System.out.println( moji.lastIndexOf('F'));
		if (  moji.indexOf('C')  >= 0 &&  moji.lastIndexOf('F') > 0 && moji.indexOf('C') < moji.lastIndexOf('F')){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}


	}

}


Measured memory_bytes: 9684
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>l(m);
    vector<int>r(m);
    for(int i=0;i<m;i++)
    {
        cin>>l[i]>>r[i];

    }
    sort(l.begin(),l.end());
    sort(r.begin(),r.end());
    int a=r[0]-l[m-1]+1;
    if(a<0)a=0;
    cout<<a;
}


Measured memory_bytes: 4044
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();
    let t: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut count: usize = 0;
    for i in 0..s.len() {
        if s[i] != t[i] {
            count += 1;
        }
    }
    return count.to_string();
}


Measured memory_bytes: 3964
import math
a, b, theta = map(int, input().split())
theta = math.radians(theta)
S = a * b * math.sin(theta) / 2
L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(theta)) + a + b
h = b * math.sin(theta)
print("{:.4f}\n{:.4f}\n{:.4f}".format(S, L, h))


Measured memory_bytes: 5716
#include "bits/stdc++.h"
#define all(v) (v).begin(), (v).end()
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define int long long
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(),(v).end()
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}

vector<string > ans;
signed main()
{
	ios::sync_with_stdio(0);
	vector<string> v;
	int n;cin>>n;
	rep(i,1,n){
		string s;cin>>s;v.pb(s);
	}
	sort(all(v));int mx=0;
	for(int i=0;i<v.size();i++){
		int p=i;
		while(p+1<v.size() && v[p+1] == v[p])p++;
		int cnt=p-i+1;
		if(cnt>mx){
			ans.clear();ans.push_back(v[p]);
			mx = cnt;
		}
		else if(cnt == mx)ans.push_back(v[p]);
		i=p;
	}
	for(auto i:ans)cout<<i<<endl;

	getchar();
	getchar();
}

Measured memory_bytes: 16368
#include <stdio.h>
#include <limits.h>
#define U 10000
#define NIL -1
#define WHITE 0
#define BLACK 1
#define MAX 100009
int d[U];
int parent[U];
int color[U];

int main(){
  int cost=0;
  int mincost;
  int i,j,k,u,v;
  int n,c;
  int A[105][105];
  scanf("%d",&n);


  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = NIL;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&c,&v);
      A[u][c] = v;
    }

  }
  
  for(u=0;u<n;u++){
    d[u] = MAX;//コスト おもさ
    parent[u] = NIL;
    color[u] = WHITE;//訪問した:BLACK   訪問まだ:WHITE
  }
  d[0]=0;//最初の島のコストは０

  while(1){
    mincost = MAX;

    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < mincost ){
	mincost = d[i];
	u = i;
      }
    }


    // printf("aiueo\n");

    if(mincost == MAX) break;

    color[u] = BLACK;

    for(v=0; v<n; v++ ){
      if(color[v] != BLACK && A[u][v] + d[u] < d[v] && A[u][v] != NIL ){
	parent[v] = u;
	d[v] =  A[u][v] + d[u]; 
      }
    }
      
  }

  // for(v=0; v<n; v++ ) cost +=  d[v];
  //  printf("%d\n",cost);

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

    
  return 0;
}




Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int A[N];REP(i,N) cin >> A[i];
    ll ans = 0;
    REP(i,N){
        REPP(j,i+1,N){
            ans += A[i]*A[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

#define MOD 10000

int main() {
	int n, k, a, b, plan[101] = { 0 }, dp[101][4][2] = { 0 };

	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		cin >> a >> b;
		plan[a] = b;
	}

	dp[1][1][0] = dp[1][2][0] = dp[1][3][0] = 1;
	for (int i = 1; i <= n; ++i) {
		if (plan[i] > 0) {
			for (int j = 1; j <= 3; ++j) {
				if (plan[i] != j)
					dp[i][j][0] = dp[i][j][1] = 0;
			}
		}
		if (i == n) break;
		for (int j = 1; j <= 3; ++j) {
			for (int k = 1; k <= 3; ++k) {
				if (j == k) {
					if (dp[i][j][0] > 0) {
						dp[i + 1][j][1] += dp[i][j][0] % MOD;
					}
				}
				else {
					dp[i + 1][k][0] += (dp[i][j][0] + dp[i][j][1]) % MOD;
				}
			}
		}
	}

	int sum = 0;
	for (int i = 1; i <= 3; ++i) {
		sum += dp[n][i][0] + dp[n][i][1];
	}

	cout << sum % MOD << endl;

	return 0;
}

Measured memory_bytes: 3072
N, M = gets.split.map(&:to_i)
W = M.times.map{ gets.split.map(&:to_i) }.sort_by(&:last)
total = 0
W.inject(-1) do |prev, w|
  if w[0] > prev 
    total += 1
    w[1] - 1
  else
    prev
  end
end
puts total


Measured memory_bytes: 12664
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
    Scanner reader=new Scanner(System.in);
    String s1 =reader.next();
    String s2 =reader.next();
    String s3 =reader.next();
    String s= s1.substring(0,1)+s2.substring(0,1)+s3.substring(0,1);
    System.out.print(s.toUpperCase());
	}
	

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int a,b;
  cin>>a>>b;
  Int h,w;
  h=w=100;
  vector<string> s(h,string(w,'.'));
  for(Int i=0;i<h;i++)
    if(i&1) s[i]=string(w,'#');

  a--;b--;
  for(Int i=0;i<h;i++)
    if(i&1) s[i][0]='.';
    else s[i][w-1]='#';

  for(Int i=0;i+5<h;i+=6){
    for(Int j=2;j+1<w;j+=2)
      if(b) s[i+1][j]='.',b--;
    for(Int j=w-3;j>0;j-=2)
      if(a) s[i+4][j]='#',a--;
  }
  
  cout<<h<<" "<<w<<endl;
  for(Int i=0;i<h;i++) cout<<s[i]<<endl;
  return 0;
}


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

#define MOD 1000000007LL

typedef long long ll;

ll extgcd(ll a, ll b, ll& x, ll& y){
  ll d = a;
  if(b != 0){
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  else{
    x = 1;
    y = 0;
  }
  return d;
}

ll mod_inverse(ll a, ll m){
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

ll fact[200002];

ll mod_fact(ll n, ll p, ll &e){
  e = 0;
  if(n == 0) return 1;
 
  ll res = mod_fact(n / p, p, e);
  e += n / p;
 
  if(n / p % 2 != 0) return res * (p - fact[(int)(n % p)]) % p;
  return res * fact[(int)(n % p)] % p;
}

ll mod_comb(ll n, ll k, ll p){
  if(n < 0 || k < 0 || n < k) return 0;
  ll e1, e2, e3;
  ll a1 = mod_fact(n, p, e1);
  ll a2 = mod_fact(k, p, e2);
  ll a3 = mod_fact(n - k, p, e3);
  if(e1 > e2 + e3) return 0;
  return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
  }
  
  ll H, W, K;

  while (cin >> H >> W >> K) {
    ll a = 0;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        // y方向の計算
        // iより下
        ll distY = H - i;
        ll distX = W - j;
        a += distY * (distY - 1) / 2 * distX;
        a %= MOD;

        // iより上
        a += i * (i + 1) / 2 * (distX - 1);
        a %= MOD;

        // x方向の計算
        a += distX * (distX - 1) / 2 * H;
        a %= MOD;
      }
    }
    
    ll b = mod_comb(H * W - 2, K - 2, MOD);

    cout << (a * b) % MOD << endl;
  }
}


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

int main()
{
    int a,b,ans;
    char op;
    
    while(1){
        cin>>a>>op>>b;

        if(op=='?')break;

        if(op=='+'){
            ans=a+b;
        }else if(op=='-'){
            ans=a-b;
        }else if(op=='*'){
            ans=a*b;
        }else if(op=='/'){
            ans=a/b;
        }
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3092
X1, X2, X3, X4, X5 = map(int, input().split())

if X1 == 0:
    print('1')
elif X2 == 0:
    print('2')
elif X3 == 0:
    print('3')
elif X4 == 0:
    print('4')
else:
    print('5')

Measured memory_bytes: 9176
#include <iostream>
#include <string>
using std::string;

bool is_mmyy(const string& s) {
  if (s.size() != 4) {
    return false;
  }
  if ('2' <= s.at(0)) {
    return false;
  }
  if (s.at(0) == '1' && '0' <= s.at(1) && s.at(1) <= '2') {
    return true;
  }
  if (s.at(0) == '0' && s.at(1) != '0') {
    return true;
  }
  return false;
}

bool is_yymm(const string& s) {
  if (s.size() != 4) {
    return false;
  }
  if ('2' <= s.at(2)) {
    return false;
  }
  if (s.at(2) == '1' && '0' <= s.at(3) && s.at(3) <= '2') {
    return true;
  }
  if (s.at(2) == '0' && s.at(3) != '0') {
    return true;
  }
  return false;
}

int main()
{
  string s;
  std::cin >> s;
  if (is_yymm(s) && is_mmyy(s)) {
    std::cout << "AMBIGUOUS\n";
  } else if (is_yymm(s)) {
    std::cout << "YYMM\n";
  } else if (is_mmyy(s)) {
    std::cout << "MMYY\n";
  } else {
    std::cout << "NA\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
string s[3];
while(cin>>s[0]){
if(s[0]=="0")break;
cin>>s[1]>>s[2];
if(s[0][0]!='+'&&s[0][0]==s[0][1]&&s[0][1]==s[0][2]){cout<<s[0][0]<<endl;continue;}
if(s[1][0]!='+'&&s[1][0]==s[1][1]&&s[1][1]==s[1][2]){cout<<s[1][0]<<endl;continue;}
if(s[2][0]!='+'&&s[2][0]==s[2][1]&&s[2][1]==s[2][2]){cout<<s[2][0]<<endl;continue;}
if(s[0][0]!='+'&&s[0][0]==s[1][0]&&s[1][0]==s[2][0]){cout<<s[0][0]<<endl;continue;}
if(s[0][1]!='+'&&s[0][1]==s[1][1]&&s[1][1]==s[2][1]){cout<<s[0][1]<<endl;continue;}
if(s[0][2]!='+'&&s[0][2]==s[1][2]&&s[1][2]==s[2][2]){cout<<s[0][2]<<endl;continue;}
if(s[0][0]!='+'&&s[0][0]==s[1][1]&&s[1][1]==s[2][2]){cout<<s[0][0]<<endl;continue;}
if(s[0][2]!='+'&&s[0][2]==s[1][1]&&s[1][1]==s[2][0]){cout<<s[0][2]<<endl;continue;}
cout<<"NA"<<endl;
}
return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    int h[100000];
    int c[100000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> h[i];
        c[i] = -1;
    }
    if(N == 2){
        cout << abs(h[0] - h[1]) << endl;
        return 0;
    }
    c[0] = 0;
    for(int i = 0; i < N - 2; i++){
        int cost01 = abs(h[i+1] - h[i]);
        if(c[i+1] == -1 || cost01+c[i] < c[i+1]){
            c[i+1] = cost01+c[i];
        }
        int cost02 = abs(h[i+2] - h[i]);
        if(c[i+2] == -1 || cost02+c[i] < c[i+2]){
            c[i+2] = cost02+c[i];
        }
    }
    int cost01 = abs(h[N-1] - h[N-2]);
    if(c[N-1] == -1 || cost01+c[N-2] < c[N-1]){
        c[N-1] = cost01+c[N-2];
    }
    cout << c[N-1] << endl;
    return 0;
}


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

int main()
{
	int N, D;
	int count = 0;
	int t;
	cin >> N >> D;
	t = D + 1;
	count = 1;
	count = N / (D * 2+1);
	if (N%(D * 2+1) != 0)
		count += 1;
	cout << count;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    bool flag=true;
    rep(i,n-1){
        if(a.at(i)==a.at(i+1))flag=false;
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<map>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
const int N = 500;
char m[N][N+1];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

bool cango(int r,int c,int y,int x,int ty,int tx){
  rep(i,4){
    int tmpx=x,tmpy=y;
    int ddx=dx[i],ddy=dy[i];
    x+=ddx;
    y+=ddy;
    while(y != -1 && x != -1 && y != r && x != c){
      if (m[y][x] != '.')break;
      if (y == ty && x == tx)return true;
      x+=ddx;
      y+=ddy;
    }
    x=tmpx;
    y=tmpy;
  }
  return false;
}

bool erase(int r,int c,int y1,int x1,int y2,int x2){
  vector<int> tx,ty;
  if (y1 == y2){
    tx.push_back(x1 < x2?x1+1:x2+1);
    ty.push_back(y1);
  }else if (x1 == x2){
    tx.push_back(x1);
    ty.push_back(y1 < y2?y1+1:y2+1);
  }else {
    tx.push_back(x1);
    ty.push_back(y2);

    tx.push_back(x2);
    ty.push_back(y1);
  }
  bool isok=false;
  rep(i,(int)tx.size()){
    //cout <<"target " << m[y1][x1] <<" " << ty[i] <<" " << tx[i] <<" : "  << y1 <<" " <<x1 <<" " << y2 <<" " << x2 << endl;
    if (cango(r,c,y1,x1,ty[i],tx[i]) && 
	cango(r,c,y2,x2,ty[i],tx[i])){isok=true;break;}
  }
  if (isok)m[y1][x1]=m[y2][x2]='.';
  return isok;
}

main(){
  int r,c;
  while(cin>>r>>c){
    rep(i,r)cin>>m[i];
    vector<pii> in[26];
    rep(i,r){
      rep(j,c){
	if (!isalpha(m[i][j]))continue;
	in[m[i][j]-'A'].push_back(make_pair(i,j));
      }
    }
    rep(i,26){
      if (in[i].size() == 0)continue;
      if (abs(in[i][0].first-in[i][1].first)+abs(in[i][0].second-in[i][1].second) == 1)in[i].clear();
    }
    int ans=0;
    while(true){
      bool iserased=false;
      rep(i,26){
	if (in[i].size() == 0)continue;
	if (erase(r,c,in[i][0].first,in[i][0].second,in[i][1].first,in[i][1].second))ans+=2,iserased=true,in[i].clear();
      }
      /*
      cout <<"dbg" << endl;
      rep(i,r){
	rep(j,c)cout << m[i][j] <<" ";
	cout << endl;
      }
      cout <<"dbgend" << endl;
      */
      if (!iserased)break;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll int64_t
#define inf LLONG_MAX

void solve()
{
	ll n,i,ans;
	cin>>n;

	for(i=0;;i++)	
	{
		ll x=i*1000;
		if(x>=n)
		{
			ans=i;
			break;
		}
		
	}
	
	cout<<((ans*1000)-n);

}


signed main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		solve();
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 3772
import java.io.*;
import java.util.*;

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() {
        int[] a = new int[4];
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
            if (i != 0) {
                a[i] = Math.min(a[i], a[i - 1] * 2);
            }
        }
        long need = in.nextLong() * 4;
        long res = (need / 8) * a[3];
        need %= 8;
        for (int i = 0; i < 3; i++) {
            if (((1 << i) & need) != 0) {
                res += a[i];
            }
        }
        out.println(res);
    }

    private void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

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

int main() {
    int n;
    double x[20];
    string u[20];
    double ans = 0.0;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> u[i];
    }
    
    for (int i = 0; i < n; i++) {
        if (u[i] == "JPY") {
            ans += x[i];
        }
        else {
            ans += x[i] * 380000.0;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int K,N,a;
    vector<int> A;
    cin >> K >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    A.push_back(A[0]+K);
    int Ans=-INF;
    REP(i,N){
        Ans=max(Ans,A[i+1]-A[i]);
    }
    cout << K-Ans << endl;
    return 0;
}



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

using namespace std;
int n;
int d[100001];
int a[100001];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        d[i]=INT_MAX;
    }
    d[1]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=i+2;j++)
        {
            d[j]=min(d[j],d[i]+abs(a[i]-a[j]));
        }
    }
    cout<<d[n];
    return 0;
}


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

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Set<Integer> set = new HashSet<>();

		for (int i = 0; i < n; i++) {
			set.add(scanner.nextInt());
		}

		System.out.println(set.size());
	}
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

struct edge {
	int to;
	long long cost;
};

vector<edge> G[100'100];

void bfs(int N, int v, vector<bool> &used, vector<long long> &dist, bool &good, long long cost){
	if (used[v]){
		if(dist[v] != cost) good = false;
	} else {
		used[v] = true;
		dist[v] = cost;
		for (int i = 0; i < G[v].size(); i++) bfs(N, G[v][i].to, used, dist, good, cost+G[v][i].cost);
	}
}
int main()
{
	int N, M;
	cin >> N >> M;

	for (int i = 0; i < M;i ++){
		int L, R, D;
		cin >> L >> R >> D;
		L--, R--;
		G[L].push_back((edge) {R,D});
		G[R].push_back((edge) {L,-D});
	}

	vector<bool> used(N, false);
	vector<long long> dist(N, -1);
	dist[0] = 0;
	bool good = true;

	for(int i = 0; i < N; i++){
		if(!used[i]){
			dist[i] = 0;
			bfs(N, i, used, dist, good, 0LL);
		}
	}
	if(good) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 21440
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <climits>
#include <map>
#include <queue>
#include <cmath>

using namespace std;

using int64 = long long;


int main() {
    int n;
    cin >> n;
    map<char,int64> mp;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        mp[s.front()]++;
    }

    int64 ans = 0;
    vector top = {'M','A','R','C','H'};
    for (int i=0; i<5; i++) {
        for (int j=i+1; j<5; j++) {
            for (int k=j+1; k<5; k++) {
                ans += mp[top[i]] * mp[top[j]] * mp[top[k]];
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3172
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		//カードの枚数を受け取る
		String card = sc.next();
		int cn = Integer.parseInt(card);
		
		//カードのマーク別に可変長配列を作る
		ArrayList<Integer> cardS = new ArrayList<Integer>();
		ArrayList<Integer> cardH = new ArrayList<Integer>();
		ArrayList<Integer> cardC = new ArrayList<Integer>();
		ArrayList<Integer> cardD = new ArrayList<Integer>();
		
		//入力されるカード番号を受け取る
		for(int i = 0; i < cn; i++){
			String kc = sc.next();
			String s2 = sc.next();
			int c = Integer.parseInt(s2);
			
			if(kc.equals("S")){
				cardS.add(c);
			}
			else if(kc.equals("H")){
				cardH.add(c);
			}
			else if(kc.equals("C")){
				cardC.add(c);
			}
			else if(kc.equals("D")){
				cardD.add(c);
			}
		}
		
		//カードのマーク別に１から１３まで受け取った番号があるかを調べる
		//なかったらその番号を表示する
		
		//トランプのマークを識別するための文字列cs
		String cs = "S";
		//今比べている配列内の値を入れる器cb
		int cb = 0;
		for(int i = 0; i < 4; i++){
			//スペードのとき
			if(cs.equals("S")){
				for(int j = 1; j <= 13; j++){
					for(int k = 0; k < cardS.size(); k++){
						cb = cardS.get(k);
						if(j == cb){
							break;
						}
						else if(k == cardS.size() - 1 && j != cb){
							System.out.println("S" + " " + j);
						}
					}
				}
				cs = "H";
			}
			//ハートのとき
			else if(cs.equals("H")){
				for(int j = 1; j <= 13; j++){
					for(int k = 0; k < cardH.size(); k++){
						cb = cardH.get(k);
						if(j == cb){
							break;
						}
						else if(k == cardH.size() - 1 && j != cb){
							System.out.println("H" + " " + j);
						}
					}
				}
				cs = "C";
			}
			//クローバーのとき
			else if(cs.equals("C")){
				for(int j = 1; j <= 13; j++){
					for(int k = 0; k < cardC.size(); k++){
						cb = cardC.get(k);
						if(j == cb){
							break;
						}
						else if(k == cardC.size() - 1 && j != cb){
							System.out.println("C" + " " + j);
						}
					}
				}
				cs = "D";
			}
			//ダイヤのとき
			else if(cs.equals("D")){
				for(int j = 1; j <= 13; j++){
					for(int k = 0; k < cardD.size(); k++){
						cb = cardD.get(k);
						if(j == cb){
							break;
						}
						else if(k == cardD.size() - 1 && j != cb){
							System.out.println("D" + " " + j);
						}
					}
				}
			}
		}
	}

}

Measured memory_bytes: 17168
#include<bits/stdc++.h>
using namespace std;
int x[55],y[55],n;
int cal(int p,int q)
{
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        bool flag=0;
        for(int j=1;j<=n;j++)
        {
            if(i==j)
                continue;
            if(x[i]+p==x[j]&&y[i]+q==y[j])
                flag=1;
        }
        if(!flag)
            ans++;
    }
    return ans;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>x[i]>>y[i];
    int ans=n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i==j)
                continue;
            ans=min(ans,cal(x[i]-x[j],y[i]-y[j]));
        }
    }
    cout<<ans<<endl;
}


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

int main(){
  char str[4];
  int num = 0;
  cin >> str;
  for(int i=0; i<3; ++i){
    if (*(str+i)=='1'){
      num++;
    }
    else if(*(str+i)!='0'){
      return 0;
    }
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let s: Vec<bool> = buf.trim_right().chars().map(|c| c == '1').collect();
    let n = s.len();
    let mut cnt = n % 2;
    let base = s[n / 2];
    while cnt != n {
        let rem = (n - cnt) / 2;
        if s[rem - 1] == base && s[n - rem] == base {
            cnt += 2;
        } else {
            break;
        }
    }
    writeln!(output, "{}", (n + cnt) / 2).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "010
",
            "2\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "100000000
",
            "8\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "00001111
",
            "4\n",
        );
    }
}

Measured memory_bytes: 4352
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, p = na()
a = na()

e, o = 0, 0
for i in range(n):
    e += a[i] % 2 == 0
    o += a[i] % 2 == 1

if o == 0:
    if p == 1:
        print(0)
    else:
        print(1 << n)
else:
    print(1 << (n - 1))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;

struct UnionFind {
    vector<int> par, weight;
    UnionFind(int n) :par(n,-1), weight(n) {}
    void unite(int x, int y, int w = 0) {
        x = root(x); y = root(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y), w = -w;
        par[x] += par[y];
        par[y] = x;
        return;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) {
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    int sizeOf(int x) { return -par[root(x)]; }
};

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,M;cin>>N>>M;
    vector<int> p(N);
    for(int i=0;i<N;++i){
        cin>>p[i]; --p[i];
    }

    int x,y;
    UnionFind uf(N);
    for(int i=0;i<M;++i){
        cin>>x>>y;
        uf.unite(--x,--y);
    }
    int ans = 0;
    for(int i=0;i<N;++i){
        if(i!=p[i] && !uf.same(i,p[i])) ++ans;
    }
    cout << N - ans << '\n';
    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
public class Main{ 
  public static void main(String[] args) { 
    Scanner sc = new Scanner(System.in);
    while(true){
      int H = sc.nextInt(); 
      int W = sc.nextInt();
      if (H == 0 && W == 0){ 
        break; 
      }
      for(int a=0;a<W;a++){
        System.out.print("#");
      }
      System.out.println("");
      for(int i=0;i<H-2;i++){
        for(int j=0;j<W;j++){
          if(j==0 || j==W - 1){
            System.out.print("#");
          }
          else {
            System.out.print(".");
          }
        }
        System.out.println("");
      }
      for(int a=0;a<W;a++){
        System.out.print("#");
      }
    System.out.println("\n");
    }
  }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while(!(str = br.readLine()).equals("-")){
			StringBuilder sb = new StringBuilder(str);
			int n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; i++) {
				int h = Integer.parseInt(br.readLine());
				sb.append(sb.toString().substring(0, h));
				sb.delete(0, h);
			}
			System.out.println(sb.toString());
		}
	}

}

Measured memory_bytes: 16916
from itertools import permutations
def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))

    T = list(permutations(list(range(1, N + 1))))
    a = T.index(P)
    b = T.index(Q)
    print(abs(a - b))

main()




Measured memory_bytes: 8052
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    vector<int>a(3), b(3);
    int f = 0, s = 0, t = 0, o = 0;
    for (int i = 0; i < 3; i++) {
        cin >> a[i] >> b[i];
        switch (a[i]) {
            case 1: f++; break;
            case 2: s++; break;
            case 3: t++; break;
            case 4: o++; break;
        }
        
        switch (b[i]) {
            case 1: f++; break;
            case 2: s++; break;
            case 3: t++; break;
            case 4: o++; break; 
        }
    }
    
    if (f >= 3 || s >= 3 || t >= 3 || o >= 3) cout << "NO";
    else if (f < 3 && s < 3 && t < 3 && o < 3) cout << "YES";
}


Measured memory_bytes: 256
import collections
X,N = map(int, input().split())
P = list(map(int, input().split()))
cnt = collections.Counter(P)

minX = X
maxX = X
for i in range(100):
    if cnt[minX] == 0:
        print(minX)
        exit()
    elif cnt[maxX] == 0:
        print(maxX)
        exit()
    else:
        minX -= 1
        maxX += 1


Measured memory_bytes: 9468
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a[] = new int[3];
    a[0]=sc.nextInt();
    a[1]=sc.nextInt();
    a[2]=sc.nextInt();
    Arrays.sort(a);
    System.out.println(a[0]+a[1]);
    

  }
  

  
}


Measured memory_bytes: 21716
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		BigInteger ans = BigInteger.ONE;
		
		BigInteger border = BigInteger.ONE;
		for (int i = 0; i < 18; i++) {
			border = border.multiply(BigInteger.valueOf(10));
		}
		
		boolean overFlg = false;
		for (int i = 0; i < n; i++) {
			if (overFlg) {
				// 0かだけチェック
				if (BigInteger.ZERO.equals(new BigInteger(sc.next()))) {
					ans = BigInteger.ZERO;
					break;
				}
			} else {
				// ボーダー以下
				ans = ans.multiply(new BigInteger(sc.next()));
				if (ans.equals(BigInteger.ZERO)) {
					// 0終了
					break;
				}
				if (ans.compareTo(border) > 0) {
					// ボーダー越え
					ans = BigInteger.valueOf(-1);
					overFlg = true;
				}
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 59208
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  };
  ($e:expr => $i:expr; $t:ty) => {
    (0..$i).map(|_| $e.get::<$t>()).collect::<Vec<$t>>()
  };
  ($e:expr => $row:expr, $col:expr; $t:ty) => {
    (0..$i).map(|_| scan!($e => $col; $t)).collect::<Vec<$t>>()
  }
}

struct Scanner<R: Read> {
  reader: R
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader }
  }
  fn safe_get<T: FromStr>(&mut self) -> Option<T> {
    let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
      .skip_while(|c| c.is_whitespace())
      .take_while(|c| !c.is_whitespace())
      .collect::<String>();
    if token.is_empty() { None } else { token.parse().ok() }
  }
  fn get<T: FromStr>(&mut self) -> T {
    if let Some(v) = self.safe_get() { v } else {
      writeln!(stderr(), "Terminated with EOF").unwrap();
      std::process::exit(0);
    }
  }
}

trait Writable {
  fn write(&self, sep: &'static str) -> String;
}

impl<T: ToString> Writable for Vec<T> {
  fn write(&self, sep: &'static str) -> String {
    self.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep)
  }
}

macro_rules! max {
  ($v0:expr, $v1:expr) => { max($v0, $v1) };
  ($v0:expr, $v1:expr, $($v:expr),*) => { max!(max($v0, $v1), $($v), *) }
}

macro_rules! min {
  ($v0:expr, $v1:expr) => { min($v0, $v1) };
  ($v0:expr, $v1:expr, $($v:expr),*) => { min!(min($v0, $v1), $($v), *) }
}


fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let n = scan!(sc; i32);
  let p = scan!(sc => n; i32);

  let mut ans = 0;
  for i in 1..(p.len() - 1) {
    if max!(p[i - 1], p[i], p[i + 1]) != p[i] && min!(p[i - 1], p[i], p[i + 1]) != p[i] {
      ans += 1
    }
  }

  println!("{}", ans);
}

fn max<T: Ord>(a: T, b: T) -> T { if a > b { a } else { b } }
fn min<T: Ord>(a: T, b: T) -> T { if a < b { a } else { b } }


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 3009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll fastpow(ll a, ll b){
    ll calc=1;
    for(;b>=1LL;b/=2LL){
        if((b&1LL))calc=mult(calc,a);
        a=mult(a,a);
    }
    return calc;
}
ll add_self(ll &a,ll b){
    a+=b;
    if(a>=MOD)a-=MOD;
    return a;
}
ll subt(ll a,ll b){
    if(a-b<0)return a-b+MOD;
    else return a-b;
}
vector<ll> dp(maxn,0);
vector<ll> prefix(maxn,0);
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    dp[1] = 1;
    rep(i,2,n+1){ /// position we are now
        vector<ll> new_dp(i+2,0);
        rep(j,1,i+1){
            prefix[j] = (prefix[j-1]+dp[j])%MOD;
        }
        rep(j,1,i+1){   /// number that I will put now
            ll L,R;
            if(s[i-2] == '<'){
                L = 1;
                R = j-1;
            }
            else{
                L = j;
                R = i-1;
            }
            if(L>R){
                continue;
            }
            // cout<<L-1<<" "<<R<<" "<<prefix[R]<<" "<<prefix[L-1]<<"\n";
            add_self(new_dp[j],(prefix[R]-prefix[L-1]+MOD)%MOD);
        }
        dp = new_dp;
    }
    ll ans = 0;
    rep(i,1,n+1){
        add_self(ans,dp[i]);
    }
    cout<<ans<<"\n";
    return 0;  
}   

Measured memory_bytes: 3672
# 0や1のケースに注意
# index out of range
# 貪欲

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    print(a*b)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65208
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int mt[20][20];

int main() {
	int n;
	while(n=in()){
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				mt[i][j]=in();
			}
		}
		for(i=0;i<n;i++){
			int sum=0;
			for(j=0;j<n;j++){
				sum+=mt[i][j];
			}
			mt[i][n]=sum;
		}
		for(i=0;i<=n;i++){
			int sum=0;
			for(j=0;j<n;j++){
				sum+=mt[j][i];
			}
			mt[n][i]=sum;
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",mt[i][j]);
			}
			cout<<endl;
		}
	}
	return 0;
}

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

int a[6], k;

int solve(int start)
{
  for ( int i = start; i <= 4; i++ )
  {
    if ( a[i+1] - a[start] > k )
      return 0;
  }
  return 1;
}

int main() {
  cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> k;
  int ok = 0;
  for ( int i = 1; i <= 4 ; i++ )
  {
    if ( ! solve(i) )
    {
      ok = -1;
      cout << ":(" << endl;
      break;
    }
   }
  if ( ok == 0 ) cout << "Yay!" << endl;
}

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

#define mk make_pair
#define pb push_back

typedef long long lld;
typedef pair<lld,lld> pr;
typedef priority_queue <lld> max_heap;
typedef priority_queue <lld, vector<lld>, greater<lld> > min_heap;
lld const mod = 1e9+7;

lld power(lld x, lld y)
{
    lld res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

lld power_mod(lld base, lld y)
{
    lld t = 1;
    while (y > 0)
    {

        if (y % 2 != 0)
            t = (t * base) % mod;
        base = (base * base) % mod;
        y /= 2;
    }
    return t % mod;
}

lld nCrModp(lld n, lld r, lld p)
{
    if (r > n - r)
        r = n - r;
    lld C[r + 1]={0};
    C[0] = 1;

    for (lld i = 1; i <= n; i++)
    {
      for (lld j = min(i, r); j > 0; j--)
      {
        C[j] = (C[j] + C[j - 1]) % p;

      }
    }
    return C[r];
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lld n;
  cin>>n;
  lld a[n];
  lld i;
  lld tot = -1;
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    if(tot==-1)
    {
      tot = a[i];
    }
    else
    {
      tot = tot ^ a[i];
    }
  }

  lld ans[n];
  for(i=0;i<n;i++)
  {
    ans[i] = a[i]^tot;
    cout<<ans[i]<<' ';
  }
  cout<<endl;


}


Measured memory_bytes: 6732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> vec(4);
  for(int i=0;i<4;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int p=vec.at(0)*1000+vec.at(1)*100+vec.at(2)*10+vec.at(3);
  
  if(p==1479){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int i= 1;
do {
int x = i;
if(x%3==0)System.out.print(" "+i );
else{
while(true) {
    if (x % 10 == 3){
        System.out.print(" "+i);
        break;
    }
    x /= 10;
    if(x!=0)continue;
    else break;
}
}
} while (++i <= n);
System.out.println();
}
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end

ll calc(ll n,ll m,ll a,ll b){
   ll res=0;
   if(a>=m){res+=(n-1)*n*(a/m)/2; a%=m;}
   if(b>=m){res+=n*(b/m); b%=m;}
   ll y=(a*n+b)/m,x=y*m-b;
   if(y==0)return res;
   res+=(n-(x+a-1)/a)*y+calc(y,a,m,(a-x%a)%a);
   return res;
}

int main(){
   int t; scanf("%d",&t);
   rep(rot,0,t){
      ll n,m,a,b; scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
      printf("%lld\n",calc(n,m,a,b));
   }
   return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    int ans = 0;
    for(int i=0; i<N; i++) {
        if(i%2) {
            ans -= A[i];
        } else {
            ans += A[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 3e5 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;

int n, a[N];
ll prefO[N], sufO[N], prefE[N], sufE[N];

int main()
{
	GO;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
	{
		(i & 1 ? prefO : prefE)[i] = a[i];
		prefO[i] += prefO[i - 1];
		prefE[i] += prefE[i - 1];
	}
	for (int i = n; i >= 1; i--)
	{
		(i & 1 ? sufO : sufE)[i] += a[i];
		sufO[i] += sufO[i + 1];
		sufE[i] += sufE[i + 1];
	}
	ll ans = -1e18;
	if (n % 2)
	{
		vec pref(n + 2);
		ll mx = -1e18;
		for (int i = 0; i <= n+1; i += 2)
		{
			mx = max(mx, prefO[i] - prefE[i]);
			pref[i] = prefE[i] + mx;
		}
		mx = -1e18;
		for (int i = n+1; i >= 2; i-=2)
		{
			mx = max(mx, sufO[i] - sufE[i]);
			ans = max(ans, pref[i - 2] + sufE[i] + mx);
		}
	}
	else
		for (int i = 1; i <= n + 1; i+=2)
			ans = max(ans, prefO[i - 1] + sufE[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11700